Data Structures, Algorithms, Leetcode, Segment Tree, Programming.
minDifference(self, nums: List[int], queries: List[List[int]]) -> List[int]: mp = defaultdict(list) for i in range(len(nums)): mp[nums[i]].append(i) # Count the positions of elements that have occurred res = [] for l, r in queries: pre, mi = -inf, inf for k in sorted(mp): # sequentially perform