Solved LeetCode program · 977 of 1,000
#1349 · Maximum Students Taking Exam
Original English source
The seats is a list of "#", ".", "#", "#", ".", "#", ".", "#", "#", "#", "#", ".", "#", ".", "#", "#", ".", and "#". Keep a shared spots as an empty list of whole numbers. Keep a shared taken as an empty list of whole numbers. Keep a shared blocked of 0. Keep a shared best of 0.
For every spot from 0 to 17.
If item spot of seats matches ".", Place spot into spots.
For every spot from 0 to 17.
Place 0 into taken.
To inspect from spot (a whole number). Set blocked to 0.
For every other from 0 to 17.
If item other of taken is 1.
The line is other divided by 6. The column is other modulo 6. The hereline is spot divided by 6. The herecolumn is spot modulo 6. The down is the absolute value of (line minus hereline). The across is the absolute value of (column minus herecolumn). If down is at most 1 and across is at most 1, set blocked to 1, stop.
To choose from which (a whole number) with students (a whole number). If which is more than the last position of spots, set best to the larger of best and students. If which is more than the last position of spots, return. The spot is item which of spots. Choose from which plus 1 with students. Set blocked to 0. Inspect from spot.
If blocked is 0.
Set item spot of taken to 1. Choose from which plus 1 with students plus 1. Set item spot of taken to 0.
Choose from 0 with 0. Show best.
Expected stdout
4