FastPrepMaximum Grid Path Score
Problems/Maximum Grid Path Score

Maximum Grid Path Score

Datadog logoDatadog● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Firsthand reports describe a maximum-score path through a numeric matrix or maze, including a version limited to two directions. This exercise specifies right/down moves, opposite-corner endpoints, negative and empty cases, the callable and bounds. The core task matches the reports at about 80%.

Given a rectangular integer grid, find the largest score of a path from its top-left cell to its bottom-right cell. At each step move exactly one cell right or down. The path includes both endpoints and must reach the destination. Its score is the sum of the values of all visited cells.

Return the maximum score as a 64-bit integer. If there are no rows or no columns, return zero. Negative scores are allowed; you may not stop early or choose an empty route for a nonempty grid.

Function

maximumGridPathScore(grid: int[][]) → long

Examples

Example 1

grid = [[1,2,3],[4,5,6]]return = 16

The best route visits 1,4,5,6: down, right, right. Its sum is 16. The other two routes sum to 12 and 14.

Example 2

grid = [[-1,-2],[-3,-4]]return = -7

The two complete routes score -1-2-4=-7 and -1-3-4=-8. Choose -7. A route must still reach the destination, so returning zero is invalid.

Example 3

grid = []return = 0

There are no cells and no route, so the defined empty-grid result is zero.

Constraints

  • 0 <= grid.length <= 50
  • Every row contains the same number of entries, between 0 and 50, inclusive.
  • -1000000000 <= grid[r][c] <= 1000000000

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public long maximumGridPathScore(int[][] grid) {
    // Write your code here.
}
Checking account…