Python 3 ||  w/ comments
\nclass ExamRoom:\n\n    def __init__(self, n: int):\n        self.n, self.room = n, []\n\n\n    def seat(self) -> int:\n        if not self.room: ans = 0      
```\nclass ExamRoom:\n\n    def __init__(self, n: int):\n        self.n, self.room = n, []\n\n\n    def seat(self) -> int:\n        if not self.room: ans = 0                           # sit at 0 if empty room \n\n        else:\n            dist, prev, ans = self.room[0], self.room[0], 0 # set best between door and first student   \n\n            for curr in self.room[1:]:                      # check between all pairs of students  \n                d = (curr - prev)//2                        # to improve on current best\n\n                if dist < d: dist, ans = d, (curr + prev)//2\n                prev = curr\n\n            if dist < self.n - prev-1: ans = self.n - 1     # finally, check whether last seat is best\n\n        insort(self.room, ans)                              # sit down in best seat\n\n        return ans\n\n    def leave(self, p: int) -> None:\n        self.room.remove(p)\n```\n[https://leetcode.com/problems/exam-room/submissions/1272745920/](https://leetcode.com/problems/exam-room/submissions/1272745920/)\n\n
['Python3']