Not able to get python O(nlogn) solution to this problem. This problem can be solved by using set in C++, is there any replacement of it in python, or some implementation you have, which could be used in competitive programming platforms, please share.
The problem is: You are given an array A of size N initially filled with 0. You have to process Q queries which are of two types:
1 i — Set Ai to 1.
2 i — Find the index of the nearest 0 to i. If there are two indices which are nearest to i print the index which is the smallest.
It is guanranteed that there will be atleast one 0 present in the entire array for query of type 2