Ctrl K

Descent That Switches Columns

Hard
You are given a square n × n table board of integers. A descent picks exactly one number in every row, top to bottom, such that the picks from any two neighbouring rows are never in the same column. Return the smallest possible sum of a descent.
Example 1
board=[[2, 9, 4], [5, 1, 8], [6, 3, 7]] → 9

Picking 2, 1, 3 is tempting, but 1 and 3 share a column. The best is 2, 1, 6, summing to 9; 2, 1, 7 would give 10.

Example 2
board=[[-5, 0], [-4, 3]] → -4

-5 and -4 sit in the same column, so it's either -5 and 3 (sum -2) or 0 and -4 (sum -4). The answer is -4.

Example 3
board=[[42]] → 42
Constraints
  • 1 ≤ n ≤ 200, and board is an n × n table
  • -99 ≤ board[i][j] ≤ 99
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBiggest Solid Panel Block HardCrossing the Cave HardLongest Uphill Walk HardWeeks of Rest by Flight HardBerry Field Round Trip Hard
loading Python…
Input
board=[[2, 9, 4], [5, 1, 8], [6, 3, 7]]
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 65 tests on the server, hidden ones included.