C++ O(nlogn) || Map || Binary Search
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\n\nclass Solution {\npublic:\n\n    vector<int> maximumBeauty(vector<vector<int>>& it
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n```\nclass Solution {\npublic:\n\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        int n=items.size(), m=queries.size();\n        \n        map<int,int> mp;\n        \n        for(int i=0;i<n;i++){\n            int p=items[i][0], b=items[i][1];\n            if(mp.find(p)==mp.end()){\n                mp[p]=b;\n            }else{\n                int prev=mp[p];\n                mp[p]=max(prev,b);\n            }\n        }\n        map<int,int> :: iterator it;\n        int maxb=-1;\n        for(it=mp.begin();it!=mp.end();it++){\n            int p=it->first;\n            int b=mp[p];\n            maxb=max(maxb,b);\n            mp[p]=maxb; // maximum beauty possible till price [1,p]\n        }\n        \n        vector<int> ans(m,0);\n        for(int i=0;i<m;i++){\n            int p=queries[i];\n            \n            if(mp.find(p)!=mp.end()){\n                ans[i]=mp[p];\n            }else{\n                auto it = mp.lower_bound(p); // checking beauty for price just lower than for given query\n                if(it!=mp.begin()){\n                    --it;\n                    ans[i]=it->second;\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```\n\n**Do Upvote If it Helps**
['Binary Tree', 'C++']