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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

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
Dynamic Programming
Multi-Agent State
Grid Paths
Rolling Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported