TreeSet Solution Design
\n\n# Code\n\nclass ExamRoom {\n\n    int capacity;\n    TreeSet<Integer> ts;\n\n//TC:-O(1)\n    public ExamRoom(int n) {\n        this.capacity = n;\n        t
\n\n# Code\n```\nclass ExamRoom {\n\n    int capacity;\n    TreeSet<Integer> ts;\n\n//TC:-O(1)\n    public ExamRoom(int n) {\n        this.capacity = n;\n        this.ts = new TreeSet<>();\n    }\n    \n\n// TC:- O(N)\n    public int seat() {\n       int count=0;\n       if(ts.size() > 0){\n           Integer prev = null;\n            int dis = ts.first();\n            for(Integer i : ts){\n                if(prev != null){\n                    int d = (i-prev)/2;\n                    if(dis < d){\n                        dis = d;\n                        count = prev +dis;\n                    }\n                }\n                prev = i;\n            }\n\n            if(dis < capacity-1-ts.last()) count = capacity-1;\n       } \n       ts.add(count);\n       return count;\n    }\n    \n\n// TC:- O(1)\n    public void leave(int p) {\n        ts.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```
['Design', 'Heap (Priority Queue)', 'Ordered Set', 'Java']