Simple C++ solution using hashmap
\nclass ExamRoom \n{\n    public:\n    int n;\n    map<int,int> total;\n    ExamRoom(int N) \n    {\n        n=N;\n    }\n    \n    int seat() \n    {\n        
```\nclass ExamRoom \n{\n    public:\n    int n;\n    map<int,int> total;\n    ExamRoom(int N) \n    {\n        n=N;\n    }\n    \n    int seat() \n    {\n        int index=-1;\n        if(total.size()==0)\n        {\n            total[0]=1;\n            return 0;\n        }\n        else\n        {\n            int last=-1;\n            int M=0;\n            for(map<int,int>::iterator it=total.begin();it!=total.end();it++)\n            {\n                if(last==-1)\n                {\n                    M=it->first;\n                    index=0;\n                }\n                else\n                {\n                    if((it->first-last)/2>M)\n                    {\n                        M=(it->first-last)/2;\n                        index=(last+it->first)/2;\n                    }\n                }\n                last=it->first;\n            }\n            if(n-1-last>M)\n            {\n                total[n-1]=1;\n                index=n-1;\n            }\n            else\n            {\n                total[index]=1;\n            }\n            return index;\n        }\n    }\n    \n    void leave(int p) \n    {\n        total.erase(p);\n    }\n};\n```
[]