Very simple C++ solution using set
\npublic:\n    int last;\n    set<int> s;\n    ExamRoom(int n) {\n        last = n-1;\n    }\n    \n    int seat() {\n        if(s.empty()){  //if the set is em
```\npublic:\n    int last;\n    set<int> s;\n    ExamRoom(int n) {\n        last = n-1;\n    }\n    \n    int seat() {\n        if(s.empty()){  //if the set is empty, occupy the first seat\n            s.insert(0);\n            return 0;\n        }\n        \n        //now we iterate over all the intervals\n        //to check which interval produces the greatest difference\n        \n        int left=0, diff=INT_MIN, pos=-1;\n        \n        //if 0 is not in set then we have to check the interval [0, first occupied seat] also \n        //if this interval produces the maximum difference then the student must occupy the 0th seat\n        if(s.find(0)==s.end()){\n            if(*s.begin()>diff){\n                diff = *s.begin();\n                pos = 0;\n            }\n        }\n        \n        //this loop checks the intervals like [1st occupied seat, 2nd occupied seat],\n        //[2nd occupied seat, 3rd occuspied seat]...[second last occupied seat, last occupied seat]\n        //if an interval in this loop produces the maximum difference then the student must occupy the seat at the mid of the interval\n        for(int right: s){\n            if((right-left)/2>diff){\n                diff=(right-left)/2;\n                pos = left + (right-left)/2;\n            }\n            left = right;\n        }\n        \n        //if the n-1th seat is not occupied then we have to check the interval [last occupied seat, n-1] as well\n        //if this interval produces the maximum difference then the student must occupy the (n-1)th seat\n        if(s.find(last)==s.end()){\n            if(last-left>diff){\n                diff = last-left;\n                pos = last;\n            }\n        }\n        s.insert(pos);\n        return pos;\n    }\n    \n    void leave(int p) {\n        s.erase(p);\n    }\n};\n```\n
['C', 'Ordered Set']