C++,set,Explained
idea is we will answer queries from largest to smalllest so when we encounter a query we ids of element whoose size is more than this query and for queries foll
idea is we will answer queries from largest to smalllest so when we encounter a query we ids of element whoose size is more than this query and for queries following this will also have size smaller than this id added.\nNow we have ids which has size larger than our query roomsize using lower_bound check closest.\n```\nclass Solution {\npublic:\n    static bool compare(vector<int>&a,vector<int>&b){\n        return a[1]>b[1];\n    }\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        int n=rooms.size();\n        int m=queries.size();\n        for(int i=0;i<m;i++)\n        {\n            queries[i].push_back(i);\n        }\n        sort(rooms.begin(),rooms.end(),compare);\n        sort(queries.begin(),queries.end(),compare);\n        vector<int>ans(m,-1);\n        int j=0;\n        set<int>s;\n        // for(auto &q:queries)\n        //     cout<<q[0]<<" "<<q[1]<<" "<<q[2]<<endl;\n        \n        for(auto &q:queries){\n            while(j<n && q[1]<=rooms[j][1]){\n                s.insert(rooms[j][0]);\n                j++;\n            }\n            if(s.empty())\n                continue;\n            // cout<<q[1]<<" "<<s.size()<<endl;\n            auto it=s.lower_bound(q[0]);\n           if(it==s.end()){\n               ans[q[2]]=*prev(it);\n           }\n            else if(it==s.begin()){\n                ans[q[2]]=*it;\n            }\n            else{\n                int h=*it;\n                int g=*prev(it);\n                if(abs(g-q[0])<=abs(h-q[0]))\n                    ans[q[2]]=g;\n                else\n                    ans[q[2]]=h;\n            }\n        }\n        return ans;\n    }\n};\n```
[]