InterviewLegend

EV Routing, Grids & Graph BFS

Alex Chen40 min readGuide updated
In this lesson
  • Route an EV to the cheapest charging station under a battery limit, from pruned DFS to Dijkstra
  • Compute every subtree size in a tree with one BFS and a reverse pass
  • Reveal a Minesweeper board with a queue and count neighbouring mines
  • Count islands with a flood fill that never visits a cell twice

Rivian's coding rounds are mostly LeetCode easy to medium, and the newest reports show the problems putting on a vehicle costume. The clearest case is from a November 2026 onsite. It was one of four one-hour rounds, and the candidate's whole note on it is short. Find a path to a charging station on a 2D array, one cell per move, start with DFS, then extend it with pruning. The same loop also asked for a vehicle-to-cloud design, and the candidate tagged the result a pass.

Graph BFS is the other live thread. A Senior AI Engineer's screen in May 2026 had a quick graph problem solved with BFS. In December 2024 a senior engineer in Palo Alto was asked how many subtrees a graph has, using BFS, and one interviewer later repeated the screen question. Two older grid problems close the lesson, each with a single dated report. Minesweeper ran in a 2023 onsite. Number of Islands comes from a 2021 remote round.

The Rivian angle
Run your code against every test before you call it done. In 2025 two Rivian candidates were offered a lower level because their solutions failed a few test cases. On a grid problem those failures hide at the edges: a start cell that is already the goal, a blocked neighbour, an empty input.

How Rivian frames grid and graph problems

Rivian has no house problem that repeats loop after loop. What repeats is a shape. You get one problem in a 45 to 60 minute session, usually on HackerRank, in the language of your choice for general software roles. Embedded and controls teams can switch you to C or C++ without much warning, so ask the recruiter which language each round expects.

The charging-station round shows how the hour tends to run. You start with something that works, here a DFS that tries every route, and the interviewer pushes you to make it faster. Pruning is the first step. The clean finish on a grid with costs is Dijkstra, and it helps to know where you're heading before you start the DFS. Rivian's job postings ban generative AI tools in live interviews, so plan to write all of it yourself.

All four problems walk a grid or graph from a start, one neighbour at a time. When every step costs the same, a plain queue gives you the order. When steps cost different amounts, as with charge per cell, a min-heap ordered by total cost takes the queue's place. Pick the structure from the costs before you write the loop.

EV route to the nearest charging station

This is the November 2026 onsite problem, and the newest grid question anyone has reported from Rivian. The candidate gave only the outline: a 2D array, a car that moves one cell at a time, a path to a charging station, DFS first and pruning after. Practice write-ups of the question put a charge cost on each cell and a battery limit on the car, and the version below does the same. Treat those details as something like the real prompt, and practice the shape.

1

EV Route to the Nearest Charging Station

MediumFrequently asked
Problem
An electric car sits on a grid at start, given as [row, col]. Each grid[row][col] is the charge it costs to drive into that cell, and -1 marks a cell the car can't enter. The car moves up, down, left or right, one cell at a time. The start cell costs nothing.

chargers lists the charging stations as [row, col] pairs, and battery is the charge the car has. The car can't enter a cell that would cost more charge than it has left. Arriving with exactly zero is fine.

Return the charge left when the car reaches the charger that costs the least charge to get to. If no charger is reachable, return -1.
Inputgrid = [[1,1,1,1],[1,-1,-1,1],[1,1,5,1]]start = [0,0]chargers = [[2,2],[2,3]]battery = 10Output5

The charger at [2,2] is fewer steps away but costs 8, because its own cell costs 5. Going along the top row and down to [2,3] costs 5, so the car arrives with 5 left.

How this uses the pattern

Weighted grid shortest path. Push (charge used, row, col) onto a min-heap. The first charger you pop is the cheapest one to reach, so you can stop there.

Write it here, or go full screen with the problem, hints and solution beside the editor.

EV Route to the Nearest Charging Station

Loading...
Click "Run" to execute your code
The Rivian angle
The candidate opened with DFS and the interviewer took it toward pruning, so be ready to walk that path out loud. A plain DFS tries every route and blows up fast. Two cuts tame it. Drop any branch that runs out of charge, and drop a cell you've already reached with at least as much charge left. Then point out that the second cut is most of the way to Dijkstra, and write the heap version.
Take it further
Return the route itself. A natural next ask is the list of cells the car drives through, start first and charger last. Keep a dict from each cell to the cell you came from, and update it whenever you find a cheaper way in. When you pop a charger, walk those parents back to the start and reverse the list. The cost and the stopping rule don't change. The walkthrough has the code.

Count subtree sizes with BFS

Two first-hand reports put graph BFS in Rivian screens. In December 2024 a senior engineer was asked "How many subtrees in a graph?" with BFS. The usual reading is every node's subtree size in a tree rooted at node 0. In May 2026 a Senior AI Engineer's screen had a quick graph problem solved with BFS, without naming it. The problem below is the subtree-size reading, and the forest count is the follow-up.

2

Subtree Sizes With BFS

MediumCommonly asked
Problem
You get n nodes numbered 0 to n - 1 and a list of undirected edges that connect them into one tree. Root the tree at node 0.

Return a list where entry i is the size of node i's subtree: the node itself plus everything below it. Use BFS for the traversal, so a deep tree can't overflow the call stack.
Inputn = 5edges = [[0,1],[0,2],[1,3],[1,4]]Output[5,3,1,1,1]

Node 1 holds itself and its children 3 and 4. The root holds all five nodes.

How this uses the pattern

BFS from node 0 gives every node a parent and an order where parents come before children. Walk that order backwards and add each node's size to its parent.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Subtree Sizes With BFS

Loading...
Click "Run" to execute your code
The Rivian angle
In that December 2024 loop one interviewer repeated the screen question, and the final technical was described as a more mathematical graph question. So don't assume a problem you've already solved is done with. Know two ways to get subtree sizes. Recursive DFS is the obvious one. BFS plus a reverse pass is the one asked for, and it doesn't hit Python's recursion limit on a long chain.
Take it further
The graph is a forest. "How many subtrees in a graph" also reads as a forest question: count the separate trees and size every node's subtree within its own tree. Loop over the nodes and start a new BFS from each one nothing has reached yet. Each start is one more tree. The reverse pass runs per tree, unchanged, and the walkthrough shows it.

Older problems (2021-2023)

The next two come from older loops, and each has one dated first-hand report. They're good practice for the same grid moves, but nothing says Rivian still asks them, so give them less time than the two problems above. A 2024 intern screen had a grid problem of its own, something like counting how many non-overlapping 2 by 2 charging stations fit on the buildable cells of a 0 and 1 grid.

Minesweeper (2023)

A software development engineer's onsite in late 2023 opened its five rounds with an algorithm round, and the candidate said it was LeetCode's Minesweeper as written. A logging-system design and behavioral rounds followed.

3

Minesweeper

MediumRarely asked
Problem
You get a Minesweeper board of single-character strings. Hidden cells are "M" for a mine and "E" for an empty cell. Revealed cells use "B" for a blank with no adjacent mines and "X" for a revealed mine. A digit from "1" to "8" marks a revealed cell next to that many mines.

click is [row, col] of the next hidden cell to reveal. A mine turns into "X". An empty cell next to at least one mine shows the count. With no adjacent mines, the cell becomes "B" and all eight neighbours are revealed by the same rules.

Return the board after the click. Adjacent means all eight directions, diagonals included.
Inputboard = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]]click = [3,0]Output[["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]

The click lands on a blank, and the reveal spreads until it reaches the ring of cells that touch the mine.

How this uses the pattern

BFS flood fill over eight directions. A cell with a mine count stops the spread; a blank pushes its hidden neighbours onto the queue.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Minesweeper

Loading...
Click "Run" to execute your code
The Rivian angle
This one came up in 2023 as the opening algorithm round of a five-round onsite. It's a flood fill with one extra rule, so the risk sits in the details. Count over eight directions, stop the spread at any numbered cell, and reveal a cell only while it's still "E". Before you say you're done, run the tiny boards: a lone mine and a lone empty cell.
Take it further
Make it safe for a huge board. Recursing on a 1,000 by 1,000 board of blanks goes a million levels deep, far past Python's limit. A queue keeps the same order of reveals without the stack. Interviewers also like asking you to build the board yourself. Place the mines, then fill each cell's count in one pass over the grid.

Number of Islands (2021)

Prep lists often rank Number of Islands as very likely at Rivian, but it has one dated first-hand report behind it. That was a November 2021 remote coding round for a software development engineer in Vancouver, in the candidate's choice of language. It's the classic flood fill, and worth twenty minutes if grids are rusty.

4

Number of Islands

MediumRarely asked
Problem
You get a 2D grid of "1" for land and "0" for water. An island is a group of land cells joined up, down, left or right. Diagonals don't connect.

Return the number of islands. The grid can be empty.
Inputgrid = [["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]Output3

A 2 by 2 block at the top left, a single cell in the middle and a pair at the bottom right.

How this uses the pattern

Scan every cell. Each time you meet land, count one island and sink the whole island with a BFS so it is never counted again.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Number of Islands

Loading...
Click "Run" to execute your code
The Rivian angle
The 2021 report gives the plain statement and nothing about follow-ups, so expect the base problem and know the extensions. It's the same neighbour walk as the charging-station problem with every step costing one, which makes it a fast warm-up for that one. Sink each cell the moment you queue it, and check the bounds before you read the grid.
Take it further
Return the size of the largest island. Count the cells as you sink each island and keep the biggest total. It's a two-line change to the BFS. A harder ask is islands that appear one cell at a time, where you report the count after each addition. Rerunning the flood fill each time is too slow there; union-find merges a new cell with its land neighbours in near-constant time.

What earns points

Passing tests counts for a lot at Rivian. Two 2025 candidates said a few failing test cases cost them a level, and a 2021 embedded screen wanted code that compiled without warnings and passed every test. So the order of work matters. Get a correct version running, run it on the edge cases out loud, and only then go after speed, the way the charging-station round moved from DFS to pruning.

Name the cost model before you code. Say whether each step costs the same or not, and pick BFS or a heap from that. On the charging problem that one sentence shows the interviewer you know why plain BFS would return the wrong charger.

Common questions

Does Rivian ask LeetCode questions?

Yes, mostly easy to medium, one problem per session in most reports. The newest ones lean toward the car, like the November 2026 charging-station route on a grid. Classic grid problems such as Minesweeper (2023) and Number of Islands (2021) each have one dated report.

What graph and grid topics should I practice for Rivian?

BFS on a grid, BFS on a tree or graph given as an edge list, and shortest paths with Dijkstra when cells cost different amounts. Be able to start from a plain DFS and prune it, because that's how the 2026 onsite round went.

What language and platform does Rivian use for coding interviews?

HackerRank, including CodePair for live rounds, in nearly every report that names a platform. General software roles let you choose the language. Embedded, controls and autonomy teams often expect C or C++. Rivian's job postings ban generative AI tools in live interviews.

Key Takeaways

  • ✓The November 2026 onsite asked for an EV route to a charging station on a grid, starting with DFS and adding pruning.
  • ✓When cells cost different amounts of charge, use Dijkstra and test for the charger when you pop it.
  • ✓Subtree sizes come from one BFS for parents and order, then a reverse pass adding each size to its parent.
  • ✓Minesweeper (2023) and Number of Islands (2021) have one dated report each. Use them as flood-fill practice.
Rivian interview guide

Know what Rivian asks before you walk in.

28 coding · 4 system design · 37 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

What Rivian Tests in CodingHad your Rivian interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.