Maximum Rocks on a North-or-East Grid Path
Updated
Problem statement
You are given a rectangular grid rocks, where rocks[row][column] is the number of rocks available in one city. Rows are ordered from south to north, and columns are ordered from west to east.
Start at the southwestern city [0, 0] and finish at the northeastern city [rows - 1, columns - 1]. From each city, you may move one row north or one column east.
Collect all rocks in every visited city, including the start and destination. Return the maximum number of rocks that can be collected.
Function
maximumCollectedRocks(rocks: int[][]) → longExamples
Example 1
rocks = [[5,1,2],[2,10,1],[1,1,20]]return = 38One optimal path visits values 5, 2, 10, 1, 20, for a total of 38.
Example 2
rocks = [[4,2,7]]return = 13With one row, the only path moves east through all three cities and collects 4 + 2 + 7 = 13.
Constraints
1 <= rocks.length <= 5001 <= rocks[row].length <= 500- Every row has the same length.
0 <= rocks[row][column] <= 10^9- The result fits in a signed 64-bit integer.
More Goldman Sachs Phone Screen questions
- House Robber IIIPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count Staircase WaysPHONE SCREEN · Seen Oct 2026
- Is a Power of TenPHONE SCREEN · Seen Oct 2026
- Minimum Traveling Salesperson TourPHONE SCREEN · Seen Oct 2026
- Square Root with Newton IterationPHONE SCREEN · Seen Oct 2026
- First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
- Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREENStripe interview questions
- Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
- Maximal SquareAirwallex · PHONE SCREENAirwallex interview questions
- Maximal SquareSalesforce · PHONE SCREENSalesforce interview questions
- Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Falling Path SumIMC Trading · PHONE SCREENIMC Trading interview questions
- Grid Paths Around Blocked CellsAdobe · PHONE SCREENAdobe interview questions
- Largest Diamond of Ones in a GridRippling · PHONE SCREENRippling interview questions
- Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW