C++: Using ordered set
Logic\n1. Ordered set is used to store occupied seats\n2. Distance between candidate seat and the nearest seat is calculated as below\n\t If end seats 0 or n-1 
# Logic\n1. Ordered set is used to store occupied seats\n2. Distance between candidate seat and the nearest seat is calculated as below\n\t* If end seats 0 or n-1 are empty, the distance between the nearest seat is same as difference between occupied seat and the end candidate seat\n\t* For seats in between. the distance is half way between two occupied seats\n\nTime complexity of seat() routine is N seats multiplied by log(N) which is Nlog(N) in worst case.\nleave() routine time complexity is log(N)\n\n```\nclass ExamRoom {\nprivate:\n\tset<int> seats;\n\tint capacity;\n\npublic:\n\n\tExamRoom(int N)\n\t{\n\t\tcapacity = N;\n\t}\n\n\tint seat()\n\t{\n\t\tint dist = 0;\n\t\tint curr = 0;\n\n\t\tif (!seats.empty()) {\n\t\t\tauto itr = seats.begin();\n            \n            //calculate distance at the begining\n\t\t\tdist = *itr;\n\n\t\t\tif (dist == 0) {\n\t\t\t\titr++;\n\t\t\t}\n            \n            //calculate distance in between\n\t\t\twhile (itr != seats.end()) {\n                int mid_dist = (*itr - *prev(itr)) / 2;\n\t\t\t\tif (dist < mid_dist) {\n\t\t\t\t\tdist = mid_dist;\n\t\t\t\t\tcurr = *prev(itr) + dist;\n\t\t\t\t}\n\t\t\t\titr++;\n\t\t\t}\n            \n            //calculate distance at the end\n\t\t\tif (dist < ((capacity - 1) - *(seats.rbegin()))) {\n\t\t\t\tcurr = capacity - 1;\n\t\t\t}\n\t\t}\n\n\t\treturn *(seats.insert(curr).first);\n\t}\n\n\tvoid leave(int p)\n\t{\n\t\tseats.erase(p);\n\t}\n};\n```
['C', 'Ordered Set', 'C++']