C++ sorting and easy solutions
\nclass Solution {\npublic:\n    static bool cmp(vector<int>&a , vector<int>&b)\n    {\n        return a[1] > b[1];\n    }\n    vector<int> closestRoom(vector<v
```\nclass Solution {\npublic:\n    static bool cmp(vector<int>&a , vector<int>&b)\n    {\n        return a[1] > b[1];\n    }\n    vector<int> closestRoom(vector<vector<int>>& rooms, vector<vector<int>>& queries) {\n        sort(rooms.begin(),rooms.end(),cmp);\n        for(int i = 0;i<queries.size();i++)\n        {\n            queries[i].push_back(i);\n        }\n        sort(queries.begin(),queries.end(),cmp);\n        int j = 0;\n        set<int>s;\n        int n = queries.size();\n        vector<int>ans(n);\n        for(int i = 0;i<queries.size();i++)\n        {\n            while(j<rooms.size() && queries[i][1] <= rooms[j][1])\n            {\n                s.insert(rooms[j][0]);\n                j++;\n            }\n            if(s.size()==0)\n            {\n                ans[queries[i][2]] = -1;\n                continue;\n            }\n            //cout<<j<<"\\n";\n            auto it = s.upper_bound(queries[i][0]);\n          //  cout<<queries[i][0]<<"\\n";\n            int val1 = INT_MAX;\n            if(it != s.end())\n            {\n                  val1 = *it;\n            }\n           \n            int val2 = INT_MAX;\n            if(it != s.begin())\n            {\n                it--;\n                val2 = *it;\n            }\n            int diff =  abs(queries[i][0]-val1);\n            int id = val1;\n         //   cout<<val1<<" "<<val2<<" "<<id<<"\\n";\n            if( (diff == abs(queries[i][0]-val2) && val2 < val1 ) ||  ( diff > abs(queries[i][0]-val2)) )\n            {\n                id = val2;\n            }\n            ans[queries[i][2]] = id;\n        }\n        return ans;\n    }\n};\n```\n\n\n\n**explaination:**\n**Please try to think after this main logic \n\nMain logic**\n\n1 see if we are finding answer of query with minSize lets say x and after that we are finding query with minsize y\nif lets say  x > y so the number of rooms that we can include is more in y \ni mean we only have to include just more rooms + rooms that we will look for y.\nso we can sort the queries in decresing order and at each time we will include all the rooms whose size is greater than or equal to queries \nwe just have to include just extra rooms and we will store ids in a set\nthe to find answer we will just find the closest one using set.\n\n**steps**\n1. sort the queries and rooms in decreasing order \n2. we will keep on adding rooms id in set till size is greater than for particular queries.\n3 the just we have to use upper_bound for solving the problem\n**Do Ask your doubts**\n
[]