Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Threshold Majority Queries

XPChallenge Points: 20
levelLevel: Medium

You are given an integer array arr of length n and a 2D array queries, where each query is represented as [l, r, limit].
For each query:
• Consider the subarray arr[l...r].
• Find the element that appears at least limit times.
• If multiple elements satisfy this condition, choose the one with the highest frequency.
• If there’s still a tie, choose the smallest element.
• If no element meets the condition, return -1 for that query.
Return an array result where result[i] corresponds to the answer for the i-th query.

Example 1:

Input: arr = [4, 5, 4, 6, 4, 5, 5] queries = [[0, 6, 3], [1, 4, 2], [2, 5, 2]]

Output: [4, 4, 5]

Example 2:

Input: arr = [2, 3, 2, 3, 2, 4, 3, 2] queries = [[0, 7, 4], [1, 5, 2], [3, 6, 2], [2, 4, 3]]

Output: [2, 3, 3, 2]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result