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
kth
nearest obstacle from the origin.Return an integer array
results
whereresults[i]
denotes thekth
nearest obstacle after queryi
, orresults[i] == -1
if there are less thank
obstacles.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 { |