Lessons learned
Code:\n\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] queries) {\n        \n        int m = items.length;\n        int n = queries.leng
**Code**:\n```\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] queries) {\n        \n        int m = items.length;\n        int n = queries.length;\n        \n        // SORT FOR BINARY SEARCH\n        Arrays.sort(items, (a, b) -> a[0] - b[0]);\n        \n        // AUXILLARY ARRAY FOR FINDING MAX IN O(1) \n        int[] maxBeauty = new int[m];\n        maxBeauty[0] = items[0][1];\n        for (int i = 1; i < m; ++i) {\n            int beauty = items[i][1];\n            maxBeauty[i] = Math.max(maxBeauty[i - 1], beauty);\n        }\n        \n        // BUILD ANSWER\n        int[] ans = new int[n];\n        for (int i = 0; i < n; ++i) {\n            int val = binarySearch(queries[i], items, maxBeauty);\n            ans[i] = val;\n        }\n        \n        return ans;\n    }\n    \n    // BINARY SEARCH\n    private int binarySearch(int maxPrice, int[][] items, int[] maxBeauty) {\n        int m = items.length;\n        int ans = 0;\n        int left = 0, right = m - 1;\n        while (left <= right) {\n            int mid = left + (right - left) / 2;\n            int price = items[mid][0];\n            if (price <= maxPrice) {\n                ans = maxBeauty[mid];\n                left = mid + 1;\n            } else {\n                right = mid - 1;\n            }\n        }\n        return ans;\n    }\n}\n```
[]