Maximum Number of Points with Cost
A medium-tier problem at 42% community acceptance, tagged with Array, Dynamic Programming, Matrix. Reported in interviews at DE Shaw and 0 others.
Maximum Number of Points with Cost is a medium-difficulty DP problem that has been asked by DE Shaw. It shows up less frequently than classic array problems, but when it does, candidates often blank on the state transitions. You're given a setup that looks like it wants a greedy approach, but it doesn't. If you hit this in a live OA and the greedy intuition fails, StealthCoder will surface a working DP solution in seconds without the proctor seeing a thing.
Companies that ask "Maximum Number of Points with Cost"
Maximum Number of Points with Cost is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trick here is recognizing that you can't just pick the max value in each row and call it done. Each choice in the current row carries a cost based on what you picked in the previous row, which means you need dynamic programming. The state is straightforward: dp[i][j] = max points ending at position j in row i. The trap is the cost calculation on transitions. A naive implementation checks all pairs of previous positions, which works but is slow. The real pattern is using a clever DP reformulation with prefix/suffix max arrays to avoid the nested loop. Most candidates who see this problem try greedy first, fail the examples, then reverse-engineer the DP. If you blank during the assessment, StealthCoder solves the DP in real time.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Number of Points with Cost recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Number of Points with Cost interview FAQ
Why doesn't greedy work on this problem?+
Greedy picks the highest-value cell in each row independently. But the cost structure penalizes picking cells that are far apart vertically and horizontally. Picking a high value early can block you from better positions later. DP explores all valid paths and tracks the true maximum.
What is the state transition?+
For each cell (i, j), you consider all cells in the previous row (i-1, k) and apply a distance-based cost. The transition is dp[i][j] = max(dp[i-1][k] - abs(j - k) * cost) + points[i][j]. You need to do this for every pair to be safe initially.
How does this problem connect to Array and Matrix topics?+
You're iterating through a 2D grid (Matrix), and the challenge is correctly updating a 1D DP array (Array) row by row. The Matrix structure defines the problem; Array operations are how you solve it efficiently.
Is this still asked after it hit DE Shaw?+
It's lower-frequency than standard DP problems. Its niche ask history means some candidates study heavy rotation problems and miss it entirely. That's exactly when StealthCoder matters most in a live OA.
What's the common mistake after you get the DP idea?+
Writing O(m*n*n) code and timing out on larger inputs. The optimization is using prefix and suffix max arrays to compute transitions in O(m*n) instead. Many candidates get the logic right but fail performance tests.
Want the actual problem statement? View "Maximum Number of Points with Cost" on LeetCode →