c++ STL set 
\n\nclass ExamRoom {\npublic:\n    ExamRoom(int N) : N(N) {\n        \n    }\n    \n    int seat() {\n        // Seat at 0 if all empty\n        if (seated.empt
```\n\nclass ExamRoom {\npublic:\n    ExamRoom(int N) : N(N) {\n        \n    }\n    \n    int seat() {\n        // Seat at 0 if all empty\n        if (seated.empty()) {\n            seated.insert(0);\n            return 0;\n        }\n        \n        // Choices:\n        // Seat at 0 if vacant\n        // Seat at N - 1 if vacant\n        // Seat at middle of max width range\n        \n        // Intialize max dist position and max distance\n        int maxPos = 0;\n        int maxDist = 0;\n        \n        // Seat at 0\n        if (!seated.count(0)) {\n            maxPos = 0;\n            maxDist = *seated.begin();\n        } \n        \n        // Seat in between occupied seats\n        auto last = seated.begin();\n        \n        for (auto it = next(seated.begin()); it != seated.end(); ++it) {\n            if (*it == *last + 1) {\n                last = it;\n                continue;\n            }\n                \n            // New seating position\n            int pos = (*it + *last) / 2;\n            \n            // New distance\n            int dist = pos - *last;\n               \n            // Select this location if bigger dist\n            if (dist > maxDist) {\n                maxDist = dist;\n                maxPos = pos;\n            }\n                \n            last = it;\n        }\n        \n        // Saet at last postion\n        if (!seated.count(N - 1)) {\n            int dist = N - 1 - *prev(seated.end());\n            \n            if (dist > maxDist) {\n                maxPos = N - 1;\n                maxDist = dist;\n            } \n        }\n        \n        // Occupy selected postion\n        seated.insert(maxPos);\n        \n        return maxPos;\n    }\n    \n    void leave(int p) {\n        seated.erase(p);\n    }\n    \nprivate:\n    int N;\n    set<int> seated;\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 \n ```
[]