All problems
Exam Room
Problem
Simulate exam seating in a room with seats numbered 0 through n - 1. An operation equal to 0 seats a student as far as possible from any other student, choosing the smallest index on ties; a positive value means the student in that seat leaves.
For each seating, compare the distance available at seat 0, at the midpoint of every gap between seated students, and at the last seat. Return the list of newly assigned seats.
Hint
Strict comparisons while scanning left to right make smaller indices win ties.
Test cases
case 1
in: [10,[0,0,0,0,4,0]]
expected: [0,9,4,2,5]
case 2
in: [1,[0,0,0]]
expected: [0,0,0]
case 3
in: [2,[0,0,1,0]]
expected: [0,1,1]
case 4
in: [6,[0,0,0,2,0]]
expected: [0,5,2,2]
case 5
in: [4,[0,0,3,0]]
expected: [0,3,3]
Starter codePython
def exam_room_seats(n, operations):
# Your code here
pass5 test cases · run your code against them in the editor