Java simple one TreeSet solution with O(N) seat and O(logN) leave
Code\n\nclass ExamRoom {\n    int N;\n    TreeSet<Integer> seats;\n    public ExamRoom(int n) {\n        seats = new TreeSet<>(); // ordered set to keep track o
# Code\n```\nclass ExamRoom {\n    int N;\n    TreeSet<Integer> seats;\n    public ExamRoom(int n) {\n        seats = new TreeSet<>(); // ordered set to keep track of students\n        this.N = n;\n    }\n    \n    public int seat() {\n        int student = 0;\n        \n        if (seats.size() > 0) { // if at least one student, otherwise seat at 0\n            int dist = seats.first(); // the student at lowest seat \n            Integer prev = null; \n            for (Integer seat: seats) { \n                if (prev != null) { \n                    int d = (seat - prev)/2; // every time we see a new student we can seat them between 2 other students\n                    if (d > dist) { // select the max range\n                        dist = d; \n                        student = prev + d; \n                    }\n                }\n                prev = seat; \n            }\n            if (N - 1 - seats.last() > dist) {\n                student = N-1;\n            }\n        }\n        seats.add(student);\n        return student;\n    }\n    \n    public void leave(int p) {\n        seats.remove(p);\n    }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(n);\n * int param_1 = obj.seat();\n * obj.leave(p);\n */\n```
['Java']