← 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
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question