C++ Solution
```\nclass ExamRoom {\nprivate:\n    setseats;\n    int capacity;\npublic:\n    ExamRoom(int n) {\n        capacity=n;\n    }\n    \n    int seat() {\n        i
```\nclass ExamRoom {\nprivate:\n    set<int>seats;\n    int capacity;\npublic:\n    ExamRoom(int n) {\n        capacity=n;\n    }\n    \n    int seat() {\n        if(seats.size()==0){\n            seats.insert(0);\n            return 0;\n        }\n        int slow=0,fast=0,mid_dist=0,mid;\n        bool first=true;\n        for(auto i:seats){\n            fast=i;\n            if(first==true){\n                if(fast-slow>mid_dist){\n                    mid_dist=fast-slow;\n                    mid=0; \n                }\n            }\n            first=false;\n            if((fast-slow)/2>mid_dist){\n                mid_dist=(fast-slow)/2;\n                mid=slow+mid_dist;\n            }\n            slow=fast;\n        }\n        if(capacity-1-fast>mid_dist){\n            mid=capacity-1;\n        }\n        seats.insert(mid);\n        return mid;\n    }\n    \n    void leave(int p) {\n        seats.erase(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 */
[]