Practice K-th Nearest Obstacle Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Initially there are no obstacles on the plane. Each query [x, y] adds an obstacle at that previously unused coordinate. After each addition, return the k-th smallest Manhattan distance |x| + |y| among all obstacles, or -1 if fewer than k obstacles exist. Return the distances in query order.
Source: K-th Nearest Obstacle Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
queries = [[1,2],[3,4],[2,3],[-3,0]], k = 2
Output
[-1,7,5,3]
# Example 2
Input
queries = [[5,5],[4,4],[3,3]], k = 1
Output
[10,8,6]
Constraints
1 <= queries.length <= 2 * 10^5
All queries[i] are unique.
-10^9 <= queries[i][0], queries[i][1] <= 10^9
1 <= k <= 10^5
Related LeetCode Problems
Practice more problems similar to K-th Nearest Obstacle Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.