#3636
Threshold Majority Queries
hard · 21.7% accepted · 37 likes · top 2%
array · hash table · binary search · divide and conquer · counting · prefix sum
Description
You are given an integer array nums of length n and an array queries, where queries[i] = [li, ri, thresholdi].
Return an array of integers ans where ans[i] is equal to the element in the subarray nums[li...ri] that appears at least thresholdi times, selecting the element with the highest frequency (choosing the smallest in case of a tie), or -1 if no such element exists.
Solution