Easy C++ Binary Search Solution || No Set Used
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    static bool cmp(vector<int>&a,vector<int>&b)\n    {\n        if(a[1]==b[1])\n        {\n            return a[
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    static bool cmp(vector<int>&a,vector<int>&b)\n    {\n        if(a[1]==b[1])\n        {\n            return a[0]<b[0];\n        }\n        return a[1]<b[1];\n    }\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& q) {\n        //sort on the basis of rooms\n        sort(rooms.begin(),rooms.end(),cmp);\n        vector<int>ans;\n        for(int i=0;i<q.size();i++)\n        {\n            int pref_id=q[i][0];\n            int min_size=q[i][1];\n            ans.push_back(fun(rooms,min_size,pref_id));\n        }\n        return ans;\n    }\n    int fun(vector<vector<int>>&rooms,int &ms,int &pId)\n    {\n        int start=0;\n        int end=rooms.size()-1;\n        int idx=-1;\n        int mid;\n        while(start<=end)\n        {\n            mid=(start+end)/2;\n            if(rooms[mid][1]>=ms)\n            {\n                idx=mid;\n                end=mid-1;\n            }\n            else\n            {\n                start=mid+1;\n            }\n        }\n        if(idx==-1)\n            return -1;\n        return fun2(rooms,idx,pId);\n    }\n    int fun2(vector<vector<int>>&rooms,int &idx,int &pId)\n    {\n        //we have to find the number closest to pId\n        //number having least distance from pId\n        int diff=abs(pId-rooms[idx][0]);\n        int ans=rooms[idx][0];\n        for(int i=idx+1;i<rooms.size();i++)\n        {\n            int temp=abs(pId-rooms[i][0]);\n            if(temp<diff)\n            {\n                diff=temp;\n                ans=rooms[i][0];\n            }\n            else if(temp==diff)\n            {\n                ans=min(ans,rooms[i][0]);\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'Binary Search', 'Sorting', 'C++']