Search
⌘K

Leetcode 1157. Online Majority Element In Subarray

Preprocess an array to support up to 10^4 queries that ask whether any value appears at least threshold times in a subarray arr[left..right] (returning that value or -1). Key constraint: 2*threshold > right-left+1 (so the target is a strict majority), so the challenge is to enable fast per-query majority detection via compact preprocessing of element positions/frequencies.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.