row: row[i] = 1 if seat i is taken and 0 if it is free. The row has at least one free seat and at least one taken seat.
You want to take a free seat so that the distance to your nearest neighbour is as large as possible. The distance between seats i and j is |i - j|.
Return that largest possible distance.row=[1, 0, 0, 0, 0, 0, 1, 0, 1] → 3
Taking seat 3 leaves the nearest neighbour 3 seats away on both sides. Nothing does better.
row=[0, 0, 0, 0, 1, 1] → 4
The best choice is the very end, seat 0: the nearest person is 4 seats away.
row=[1, 0] → 1
len(row) ≤ 10⁵row[i] is 0 or 1row=[1, 0, 0, 0, 0, 0, 1, 0, 1]
3
Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.