OOP design simplifies this to log(N) seat + leave. Java code attached.
This has better order complexity than the one mentioned in the editorial.\n\n\nclass ExamRoom {\n    final int N;\n    final IntervalQueue queue;\n    public Ex
This has better order complexity than the one mentioned in the editorial.\n\n```\nclass ExamRoom {\n    final int N;\n    final IntervalQueue queue;\n    public ExamRoom(int N) {\n        queue = new IntervalQueue(N);\n        this.N = N;\n    }\n    \n    public int seat() {\n        final Interval largestInterval = queue.poll();\n        final int partition;\n        if(largestInterval.start == 0) {\n            partition = 0;\n        } else if (largestInterval.end == N - 1) {\n            partition = N - 1;\n        } else {\n            partition = (largestInterval.start + largestInterval.end) / 2;\n        }\n        if(partition > largestInterval.start) {\n            queue.add(largestInterval.start, partition - 1);\n        } \n        if(partition < largestInterval.end) {\n            queue.add(partition + 1, largestInterval.end);\n        }\n        return partition;\n    }\n    \n    public void leave(int p) {\n        queue.add(p, p);\n        queue.merge(p);\n        queue.merge(p - 1);\n    }\n}\n\nclass Interval implements Comparable<Interval> {\n    final int start, end, size;\n    \n    public Interval(int start, int end, int N) {\n        this.start = start;\n        this.end = end;\n        int length = end - start;\n        if(start == 0 || end == N - 1) {\n            this.size = length;\n        } else {\n            this.size = length / 2;\n        }\n    }\n    \n    public int compareTo(Interval other) {\n        final int diff = other.size - this.size;\n        if(diff != 0) {\n            return diff;\n        }\n        return this.start - other.start;\n    }\n}\n\nclass IntervalQueue {\n    final TreeSet<Interval> orderedSet = new TreeSet<>();\n    final int N;\n    //map interval starting index i to it\'s ending point and vice versa\n    final Map<Integer, Integer> startToEnd = new HashMap<>(), endToStart = new HashMap<>();\n    \n    public IntervalQueue(final int N) {\n        this.N = N;\n        add(0, N - 1);\n    }\n    \n    public Interval poll() {\n        final Interval largestInterval = orderedSet.first();\n        remove(largestInterval.start, largestInterval.end);\n        return largestInterval;\n    }\n    \n    public void add(final int start, final int end) {\n        startToEnd.put(start, end);\n        endToStart.put(end, start);\n        orderedSet.add(new Interval(start, end, N));\n    }\n    \n    public void remove(int start, int end) {\n        endToStart.remove(end);\n        startToEnd.remove(start);\n        orderedSet.remove(new Interval(start, end, N));\n    }\n    \n    //Merge the two intervals separated at partition ((l , p), (p + 1, r))  -> (l, r)\n    public void merge(final int p) {\n        if(p >= 0 && p < N - 1 && startToEnd.containsKey(p + 1)  && endToStart.containsKey(p)) {\n            final int l = endToStart.get(p), r = startToEnd.get(p + 1);\n            remove(l, p);\n            remove(p + 1, r);\n            add(l, r);\n        }\n    }\n}\n```
[]