Minimum Path Sum
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reportedly served Minimum Path Sum in March 2020, and under the grid dressing it's a tiny DP, not a real graph search. Right and down only means no cycles, so each cell's best cost depends on just two neighbors. If you've got an OA invite and 48 hours, this is the kind of problem you want to see. It's short, the examples are clean, and the grid goes up to 500 by 500, so sloppy recursion will punish you. StealthCoder sits as a quiet safety net on the live OA if your mind goes blank on the recurrence, but you can own this one before then.
The problem
Given a nonempty rectangular matrix grid of nonnegative integers, start at the top-left cell and reach the bottom-right cell. At each step, move exactly one cell right or one cell down. Return the minimum possible sum of the values on the path, including both endpoints. Function minimumPathSum(grid: int[][]) → int Examples Example 1 grid = [[1,3,1],[1,5,1],[4,2,1]] return = 7 The path 1, 3, 1, 1, 1 has sum 7. Example 2 grid = [[1,2,3],[4,5,6]] return = 12 Moving right, right, then down gives 1 + 2 + 3 + 6. Example 3 grid = [[1,99,1],[1,99,1],[1,1,1]] return = 5 Advanced contract case 7. Constraints 1 <= grid.length, grid[0].length <= 500 Every row has the same length. 0 <= grid[r][c] <= 10000 The answer fits in a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: dp[r][c] = grid[r][c] + min(dp[r-1][c], dp[r][c-1]). First row only comes from the left, first column only from above. Fill row by row and return the bottom-right cell. You can even reuse the grid or keep a single row array to cut memory to O(cols). The common pitfall is reaching for Dijkstra or plain DFS because the hint says graph. DFS without memoization blows up exponentially on a 500 by 500 grid. Another miss is forgetting the edge borders and calling min on out-of-range indexes. Also check the 1-row and 1-column cases, since the constraints allow them. Example 3 is your sanity test: the detour through the 1s beats the 99s and gives 5. Time is O(rows*cols). If you freeze during the live OA, StealthCoder can surface this recurrence in seconds, but the pattern is simple enough to memorize tonight.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Minimum Path Sum cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum path sum. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Path Sum FAQ
How hard is Minimum Path Sum really?+
Easy to low-medium. It's a classic grid DP with one recurrence and two border cases. If you've seen any 2D DP before, you can code it in about ten minutes. The only real risk is overcomplicating it with graph algorithms.
What's the trick to solving it?+
Each cell's minimum cost equals its value plus the smaller of the cost from above or from the left. Moves are only right or down, so there are no cycles and no need for shortest-path machinery. Fill the table in order and read the bottom-right.
Do I need Dijkstra because the hint says graph?+
No. Dijkstra works but it's overkill and slower to write. The grid is a DAG, so a single pass of DP is enough and runs in O(rows*cols). Use the graph framing only to understand why order of filling matters.
How do I handle the first row and column?+
The first row can only be reached from the left, so it's a running prefix sum. The first column can only be reached from above, so it's also a running sum. Initialize those, then apply the min recurrence to every other cell.
How do I prepare for this in 48 hours?+
Write the DP from scratch twice, once with a full table and once with a single row array. Test on the three given examples plus a 1xN and Nx1 grid. Then do a couple of related grid DP problems so the pattern feels automatic.