Two Street View Cars Collecting Landmarks Down a City Grid
Last updated: November 29, 2026
Quick Overview
Two Street View cars start at the top-left and top-right cells of an m x n grid of landmark scores and each moves down one row per step to the diagonal-left, straight-down or diagonal-right cell; return the maximum total score collected, counting a shared cell only once.
0
0
0 solved
Two Street View cars start at the top-left and top-right cells of an m x n grid of landmark scores and each moves down one row per step to the diagonal-left, straight-down or diagonal-right cell; return the maximum total score collected, counting a shared cell only once.
A Google onsite DP question where the key insight is modeling two agents in lockstep. The interviewer checks that you see why two independent greedy or single-agent DPs fail, define the joint state cleanly, and then compress memory.
What the Interviewer Expects
- Explains why optimizing each car separately double counts or misses interactions
- Defines state as (row, col1, col2) because both cars share the row
- Handles the same-cell case by counting once
- Writes a bottom-up DP with rolling rows
- States O(m n^2 * 9) time and O(n^2) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Allow the cars to also stay in the same column without moving down; what breaks?
- Three cars instead of two: how does the state grow?
- Reconstruct the two actual routes, not just the score.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
grid, m x n non-negative ints. Car A starts at(0, 0), car B at(0, n-1). - Each step both cars move to row r+1, column changing by -1, 0 or +1, staying in bounds.
- Score is the sum of...
High-Level Design
Both cars always share the same row, so the state is just (c1, c2) for the current row. Let dp[c1][c2] be the best score after the current row with cars at those columns. Transition from each of t...