Maximum Non-Adjacent Coins in Two Rows
Updated
Problem statement
You are given a 2 × n integer grid of coin values. Choose any set of cells with maximum total value.
No two chosen cells may be horizontally, vertically, or diagonally adjacent. Choosing no cells is allowed and has total value 0.
Function
maxNonAdjacentCoins(coins: int[][]) → longExamples
Example 1
coins = [[4,5,6,7,8],[1,9,2,10,3]]return = 19Choose value 9 from column 1 and value 10 from column 3.
Example 2
coins = [[-5,-2],[-3,-4]]return = 0Skipping every negative coin is optimal.
Constraints
coins.length == 21 <= n == coins[0].length == coins[1].length <= 200000-10^9 <= coins[row][column] <= 10^9- The answer fits in a signed 64-bit integer.
Source note: Interview prompt excerpt preserved as source evidence.
More Kotak Mahindra Bank Onsite Interview questions
- Longest Common PrefixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
- Search in Rotated Sorted ArrayONSITE INTERVIEW · Seen Oct 2026
- Find the Index of the First Occurrence in a StringONSITE INTERVIEW · Seen Oct 2026
- Roman to IntegerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Subarrays Whose Sum Is a Power of TwoONSITE INTERVIEW · Seen Oct 2026
- Remove Duplicates From Sorted Array In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Course ScheduleONSITE INTERVIEW · Seen Sep 2026
- House Robber IIONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Dungeon GameAmazon · ONSITE INTERVIEW
- Dungeon GameLotusFlare · ONSITE INTERVIEW
- Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
- Maximal Rectangle in a Binary MatrixGoogle · ONSITE INTERVIEWGoogle interview questions
- Dungeon HealthGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- DSA Round: Maximum Score Grid PathOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Longest Decreasing Matrix Path with Limited RelaxationsDuolingo · ONSITE INTERVIEWDuolingo interview questions
- Longest Increasing Path in a MatrixDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions