JavaScript 100% Solution with Comments
\n/**\n * @param {number} N\n */\nvar ExamRoom = function(N) {\n    this.len=N;//For Length\n    this.seats=new Array();//For Storing Used Seats (Sorted)\n};\n\
```\n/**\n * @param {number} N\n */\nvar ExamRoom = function(N) {\n    this.len=N;//For Length\n    this.seats=new Array();//For Storing Used Seats (Sorted)\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat = function() {\n        \n        /*If all seats empty*/\n        if(this.seats.length<=0){\n            this.seats.push(0);\n            return 0;\n        }\n\n        let mx=-1;//for max diff\n        let res=-1;//for seat-index\n        \n        /*\n        Compare every 2 closest pairs of seats array\n        */\n        for(let i=0;i<this.seats.length-1;i++){\n            let avg=Math.floor((this.seats[i]+this.seats[i+1])/2);\n            let diff=avg-this.seats[i];\n            if(diff>mx){\n                mx=diff;\n                res=avg;\n            }\n        }\n        \n        /*Left Boundary*/\n        if(this.seats[0]>=mx){\n            mx=this.seats[0];\n            res=0;\n        }\n        /*Right Boundary*/\n        if((this.len-1)-this.seats[this.seats.length-1]>mx){\n            mx=(this.len-1)-this.seats[this.seats.length-1];\n            res=(this.len-1);\n        }\n    \n        /*Insert at appropriate index to maintain sorted order*/\n        let flag=0;\n        for(let i=0;i<this.seats.length;i++){\n            if(this.seats[i]>res){\n                this.seats.splice(i,0,res);\n                flag=1;\n                break;\n            }\n        }\n        if(!flag)\n            this.seats.push(res);\n    \n        /*Return result*/\n        return res;\n};\n\n/** \n * @param {number} p\n * @return {void}\n */\nExamRoom.prototype.leave = function(p) {\n    let ind=this.seats.indexOf(p);\n    this.seats.splice(ind,1);\n};\n\n/** \n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(N)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */\n```
[]