LeetCode 2070, Medium. Topics: Array, Binary Search, Sorting. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:
Problem
You are given a 2D integer array items where items[i] = [price<sub>i</sub>, beauty<sub>i</sub>] denotes the <b>price</b> and <b>beauty</b> of an item respectively.
You are also given a <b>0-indexed</b> integer array queries. For each queries[j], you want to determine the <b>maximum beauty</b> of an item whose <b>price</b> is <b>less than or equal</b> to queries[j]. If no such item exists, then the answer to this query is 0.
Return an array answer of the same length as queries where answer[j] is the answer to the j<sup>th</sup> query.
Examples
Constraints
- 1 <= items.length, queries.length <= 10^5
- items[i].length == 2
- 1 <= price_i, beauty_i, queries[j] <= 10^9
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026