Java | TreeMap | Simple | No Sorting | Explanation
Approach:\n Create TreeMap[price, max beauty of a product].\n Iterate through tree map and update the max beauty of a product with max beauty to so far.\n For e
**Approach:**\n* Create TreeMap[price, max beauty of a product].\n* Iterate through tree map and update the max beauty of a product with max beauty to so far.\n* For each query use built in floorEntry method to find the greatest price less than or equal to a query.\n\n**Complexities:**\nTime Complexity: O(N log N + Q log N)\nSpace Complexity: O(N)\n\n**Solution:**\n```\nimport java.util.*;\nclass Solution {\n    public int[] maximumBeauty(int[][] items, int[] queries) {\n        NavigableMap<Integer, Integer> map = new TreeMap<>();\n        \n        for (int[] item: items) {\n            if (map.containsKey(item[0])) {\n                map.put(item[0], Math.max(item[1], map.get(item[0])));\n            } else {\n                map.put(item[0], item[1]);\n            }\n        }\n        \n        int maxSoFar = Integer.MIN_VALUE;\n        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {\n            maxSoFar = Math.max(maxSoFar, entry.getValue());\n            entry.setValue(maxSoFar);\n        }   \n            \n        for (int i = 0; i < queries.length; ++ i) {\n            Map.Entry<Integer, Integer> entry = map.floorEntry(queries[i]);\n            if (entry == null) {\n                queries[i] = 0;\n            } else {\n                queries[i] = entry.getValue();\n            }\n        }\n        \n        return queries;\n    }\n}\n```
['Java']