3275. K-th Nearest Obstacle Queries
There is an infinite 2D plane.
You are given a positive integer
k. You are also given a 2D arrayqueries, which contains the following queries:
queries[i] = [x, y]: Build an obstacle at coordinate(x, y)in the plane. It is guaranteed that there is no obstacle at this coordinate when this query is made.After each query, you need to find the distance of the
kthnearest obstacle from the origin.Return an integer array
resultswhereresults[i]denotes thekthnearest obstacle after queryi, orresults[i] == -1if there are less thankobstacles.Note that initially there are no obstacles anywhere.
The distance of an obstacle at coordinate
(x, y)from the origin is given by|x| + |y|.
1 | class Solution { |