KOTLIN and JAVA solution - beats 100%
\u2618\uFE0F\u2618\uFE0F\u2618\uFE0F If this solution was helpful, please consider upvoting! \u2705\n\n# Intuition\nThis problem requires finding the maximum be
\u2618\uFE0F\u2618\uFE0F\u2618\uFE0F If this solution was helpful, please consider upvoting! \u2705\n\n# Intuition\nThis problem requires finding the maximum beauty of items that meet a price constraint, given multiple queries. \n\nSorting the items by price can simplify the task, allowing us to efficiently track the highest available beauty for each query using binary search.\n\n# Approach\n- Sort and Track Maximum Beauty:\n\n    - Sort items by price and sort queries while keeping track of their original indices.\n    - Traverse the sorted items to build a cumulative list of maximum beauty values up to each price, so we can easily know the maximum beauty available for any price constraint.\n- Binary Search with Queries:\n\n    - For each query (sorted in ascending order), use binary search to find the highest price that\u2019s within the query price.\n    - Retrieve the corresponding maximum beauty for that price from the precomputed list.\n- Efficiency with Binary Search:\n\n    - Using binary search on the sorted prices reduces the complexity for each query, making the solution efficient for large inputs.\n\n\n# Code\n```Kotlin []\nclass Solution {\n    fun maximumBeauty(items: Array<IntArray>, queries: IntArray): IntArray {\n        items.sortBy { it[0] }\n        \n        val maxBeautyByPrice = TreeMap<Int, Int>()\n        var maxBeauty = 0\n        \n        for ((price, beauty) in items) {\n            maxBeauty = maxOf(maxBeauty, beauty)\n            maxBeautyByPrice[price] = maxBeauty\n        }\n        \n        return queries.map { query ->\n            maxBeautyByPrice.floorEntry(query)?.value ?: 0\n        }.toIntArray()        \n    }\n}\n```\n\n```Java []\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] queries) {\n        Arrays.sort(items, (a, b) -> Integer.compare(a[0], b[0]));\n        \n        TreeMap<Integer, Integer> maxBeautyByPrice = new TreeMap<>();\n        int maxBeauty = 0;\n        for (int[] item : items) {\n            maxBeauty = Math.max(maxBeauty, item[1]);\n            maxBeautyByPrice.put(item[0], maxBeauty);\n        }\n        \n        int[] result = new int[queries.length];\n        for (int i = 0; i < queries.length; i++) {\n            Integer price = maxBeautyByPrice.floorKey(queries[i]);\n            result[i] = (price == null) ? 0 : maxBeautyByPrice.get(price);\n        }\n        \n        return result;\n    }\n}\n```
['Array', 'Binary Search', 'Sorting', 'Java', 'Kotlin']