Data Structures, Algorithms, Leetcode, Segment Tree, Programming.
binary search on each element i = bisect_left(mp[k], l) if i < len(mp[k]) and mp[k][i] <= r: if pre != -inf: mi = min(mi, k - pre) # if it is within the interval pre = k if mi < inf: res.append(mi) else: res.append(-1) return res Conclusion Through the gradual progression of our thought process, we