3
set<int> s; // ordered set6
num = n; // total seats13
} // if size is zero place at seat 015
if (s.size() == 1) { // if size==1 -> check if its closer to 0 or last seat (num-1)16
if (*itr > num - 1 - (*itr)) {24
int mx = -1; // for max gap25
int l = 0; // for left index of the student to max gap.27
if (s.find(0) == s.end()) {30
} // if 0 is not seated -> check gap with 0 and starting seat.32
// Iterate the set to calculate gaps33
for (int i = 0; i < s.size() - 1; i++) {34
int a = *itr; // seat number for 1st element36
int b = *itr; // seat number of next element in the set38
// check the gap and update39
if (mx < (b - a) / 2) {44
if (s.find(num - 1) == s.end()) { // if last seat is vacant -> check gap45
// with last filled seat and (num-1)46
if (mx < num - 1 - (*itr)) {47
mx = (num - 1 - (*itr));51
s.insert(l + mx); // place the student at l+mx56
// remove student from set