Uber Coding Interview: Arrow Grid Cheapest Route

Based on a candidate's reported Uber interview

The interviewer opens

Welcome, and thanks for joining this interview for the Senior Software Engineer L5A role at Uber. We'll work through one coding problem together, and I'd like you to think out loud as you go. If you need to step out or take a break, you can pause any time with the Pause button at the top right.

The problem is about a driver routing across a grid of one-way streets, which is a small cousin of the routing questions Uber deals with. It's up in the Problem tab now, so please read it through and ask me any questions before you start.

The problem

A driver crosses a city grid where every block has a one-way arrow, and may go against an arrow for a fee.

  • grid: list of n strings, each of length m. Each character is > (right), < (left), v (down) or ^ (up).

The driver starts at (0,0) and must reach (n-1, m-1), moving one block at a time, only right or down. A move costs 0 if it goes in the direction of the arrow on the block being left, and 1 otherwise. Return the minimum total cost of reaching the bottom-right block.

Example: grid = ["v<", "^<"] → 1

1 ≤ n, m ≤ 100.