← All questions
MediumCoding
Count Subarrays Where Max Element Appears at Least K Times
Asked at
Meta
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Find the global maximum value.
- 02Expand a right pointer and count max occurrences.
- 03Shrink left while count is at least k.
- 04Add left to the answer after shrinking.
- 05Use a wide answer type.
Reference answer
Then expect these follow-ups
Why does adding left count all valid starts?
Tests: correctness reasoning
How would you count subarrays with exactly k maxima?
Tests: follow-up reasoning
Hiring now
Get the Meta interview, not just the prep
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Next question