C# SortedSet solution
\n\n\npublic class ExamRoom {\n\n    private SortedSet<int> seats;\n    private int N;\n    \n    public ExamRoom(int n) {\n        \n        seats = new Sorted
![image](https://assets.leetcode.com/users/images/b2326164-b073-497b-84e7-db7d0550976d_1642460586.7792268.png)\n\n```\npublic class ExamRoom {\n\n    private SortedSet<int> seats;\n    private int N;\n    \n    public ExamRoom(int n) {\n        \n        seats = new SortedSet<int>();\n        N = n;\n    }\n    \n    // O(n + logn)\n    public int Seat() {\n        \n        if(seats.Count == 0)\n        {\n            seats.Add(0);\n            return 0;\n        }\n        else\n        {\n            int maxDistance = seats.First();\n            int prev = -1, res = 0;\n            foreach(var curr in seats)\n            {\n\t\t\t    // case1 & case 2\n                int currDistance = prev == -1? curr : (curr - prev) / 2;\n                if(currDistance > maxDistance)\n                {\n                    maxDistance = currDistance;\n                    res = prev + maxDistance;\n                }\n                prev = curr;\n            }\n            \n\t\t\t// case 3\n            if(N - 1 - prev > maxDistance)\n                res = N - 1;\n            \n            seats.Add(res);\n            return res;\n        }\n    }\n    \n    // log(n)\n    public void Leave(int p) {\n        \n        seats.Remove(p);\n    }\n}\n```
[]