✅ C++ || Sorting || Binary Search
Approach\n\nSteps\n\t(1) Sort the items on the basis of their price\n\t(2) prepare answer for every price in prefix\n\t(3) use binary search to find a price val
# ***Approach***\n```\nSteps\n\t(1) Sort the items on the basis of their price\n\t(2) prepare answer for every price in prefix\n\t(3) use binary search to find a price value in items which is closest to query price\n\t(4) take answer from prefix to answer a query\n\tTime : O(nlog(n) + qlog(n))\n```\n# ***Code***\n```\nclass Solution {\npublic:\n    static bool comparator(vector<int> &a , vector<int> &b)\n    {\n        return a[0] < b[0];\n    }\n    vector<int> maximumBeauty(vector<vector<int>> &nums, vector<int> &queries) {\n        vector<int> prefix;\n        sort(nums.begin() , nums.end() , comparator);\n        \n        int max_beauty = 0;\n        for(auto v : nums)\n        {\n            max_beauty = max(max_beauty , v[1]);\n            prefix.push_back(max_beauty);\n        }\n        \n        vector<int> res;\n        for(int q : queries)\n        {   \n            int x = bin_search(nums , q);\n            if(x < 0)\n                res.push_back(0);\n            else\n                res.push_back(prefix[x]);\n        }\n        return res;\n    }\n    int bin_search(vector<vector<int>> &nums , int target)\n    {\n        int left = 0 , right = nums.size() - 1;\n        while(left <= right)\n        {\n            int mid = left + (right - left) / 2;\n            if(nums[mid][0] > target)\n                right = mid - 1;\n            else\n                left = mid + 1;\n        }\n        return right;\n    }\n};\n```\n# ***If you liked the Solution, Give it an Upvote :)***
[]