Binary Search
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution \n{\n    public int[] closestRoom(int[][] rooms, int[][] queries) \n    {\n        //let\'s first sort the rooms on the \n        Arrays.sort(rooms,(a,b)->Integer.compare(a[1],b[1]));\n        int k=queries.length;\n\n        //let\'s Iterate over the each query..\'\n\n        int[]ans=new int[k];\n        for(int i=0;i<k;i++)\n        {\n            int prefId=queries[i][0];\n            int minSize=queries[i][1];\n            \n            //we\'ll first find the the perticular index which does exists or not using binary searc..\'\n            int res=bs(rooms,prefId,minSize);\n\n            if(res==-1)\n            {\n                ans[i]=-1;\n                continue;\n            }\n\n            //this function will return the index of the answer room... \n\n            int idx=find(rooms,res,prefId);\n\n            //room Id will be on oth position ..\n            ans[i]=rooms[idx][0];\n\n        }\n        return ans;\n    }\n\n    public int bs(int[][]rooms,int prefId,int minSize)\n    {\n        //This functions main motive is to Find the Left most room have size greater that or equals to minSize.\n        int ans=-1;\n        int l=0,r=rooms.length-1;\n        while(l<=r)\n        {\n            int mdi=l+(r-l)/2;\n            if(rooms[mdi][1]<minSize)l=mdi+1;\n            else{\n                ans=mdi;\n                r=mdi-1;\n            }\n        }\n        return ans;\n        \n    }\n\n    public int find(int[][]rooms,int res,int prefId)\n    {\n        //The main motive of this function si to find the room having size grater that equals to min size \n        //and to fidn the closet room to prefred Id..\n        int mn=Math.abs(rooms[res][0]-prefId);\n        int ans=res;\n        for(int i=res+1;i<rooms.length;i++)\n        {\n            //let\'s check the min diffrence for other too..\'\n            int temp=Math.abs(prefId-rooms[i][0]);\n            if(temp<mn)\n            {\n                ans=i;\n                mn=temp;\n            }\n            else if(temp==mn)\n            {\n                if(rooms[i][0]<rooms[ans][0])ans=i;\n            }\n        }\n        return ans;\n    }\n}\n\n\n\n```
['Java']