Code RoomTwo-robot cherry collection
HardPrep Room Coding #1316

Two-robot cherry collection

CodingAlgorithms & data structuresSenior–Staff~45 min

Two robots start at the top row of an m x n grid: robot A at column 0, robot B at column n-1. Each step both robots move down one row, and each may shift to an adjacent column (left, straight, or right). When a robot lands on a cell it collects its cherries; if both land on the same cell, the cherries are only counted once. Return the maximum cherries collected by the time both reach the bottom row. Constraints: 1 <= m, n <= 70, 0 <= cell <= 100.

Implement
cherry_pickup_two(grid: list[list[int]]) → int
Examples
in[[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]]out24
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 45 min
InputExpectedGot
[[[3,1,1],[2,5,1],[1,5,5],[2,1,1]]]24not run yetsample