🤔Beats 99%💥 || 💸3 Approaches💡 || 🔌Unique😅
3 Approaches:\n\n# Approach-1\n# Code\ncpp []\nclass Solution {\npublic:\n    int solve(vector<pair<int,int>>&v,int query){\n        int s=0,e=v.size()-1;\n    
# 3 Approaches:\n![image.png](https://assets.leetcode.com/users/images/23edaab9-1981-4d97-b13b-5f72e1d27c91_1728444291.3986533.png)\n# Approach-1\n# Code\n```cpp []\nclass Solution {\npublic:\n    int solve(vector<pair<int,int>>&v,int query){\n        int s=0,e=v.size()-1;\n        int ans=0;\n        while(s<=e){\n            int mid=s+(e-s)/2;\n            if(v[mid].first<=query){\n                ans=v[mid].second;\n                s=mid+1;\n            }\n            else{\n                e=mid-1;\n            }\n        }\n        return ans;\n    }\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        int n=queries.size();\n        unordered_map<int,int>mp;\n        for(auto item:items){\n            if(mp.count(item[0])){\n                if(item[1]>mp[item[0]]){\n                    mp[item[0]]=item[1];\n                }\n            }\n            else{\n                mp[item[0]]=item[1];\n            }\n        }\n        vector<pair<int,int>>v;\n        for(auto it:mp){\n            v.push_back(it);\n        }\n        sort(v.begin(),v.end());\n        for(int i=1;i<v.size();i++){\n            v[i].second=max(v[i-1].second,v[i].second);\n        }\n        vector<int>ans;\n        for(int i=0;i<n;i++){\n            ans.push_back(solve(v,queries[i]));\n        }\n        return ans;\n    }\n};\n```\n\n# Approach-2\n# Code\n```cpp []\nclass Solution {\npublic:\n    int solve(vector<vector<int>>&v,int query){\n        int s=0,e=v.size()-1;\n        int ans=0;\n        while(s<=e){\n            int mid=s+(e-s)/2;\n            if(v[mid][0]<=query){\n                ans=v[mid][1];\n                s=mid+1;\n            }\n            else{\n                e=mid-1;\n            }\n        }\n        return ans;\n    }\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        int n=queries.size();\n        sort(items.begin(),items.end());\n        for(int i=1;i<items.size();i++){\n            items[i][1]=max(items[i-1][1],items[i][1]);\n        }\n        vector<int>ans;\n        for(int i=0;i<n;i++){\n            ans.push_back(solve(items,queries[i]));\n        }\n        return ans;\n    }\n};\n```\n# Approach-3\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        int n=queries.size();\n        vector<pair<int,int>>v;\n        for(int i=0;i<n;i++){\n            v.push_back({queries[i],i});\n        }\n        sort(v.begin(),v.end());\n        sort(items.begin(),items.end());\n        for(int i=1;i<items.size();i++){\n            items[i][1]=max(items[i-1][1],items[i][1]);\n        }\n        vector<int>ans(n);\n        int j=0,maxi=0;\n        for(int i=0;i<n;i++){\n            while(j<items.size() && items[j][0]<=v[i].first){\n                maxi=max(maxi,items[j][1]);\n                j++;\n            }\n            ans[v[i].second]=maxi;\n        }\n        return ans;\n    }\n};\n```\n\n![image.png](https://assets.leetcode.com/users/images/23edaab9-1981-4d97-b13b-5f72e1d27c91_1728444291.3986533.png)
['Array', 'Binary Search', 'C', 'Sorting', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']