Trains the technique from
LeetCode 2962Count Subarrays Where Max Element Appears at Least K TimesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A log holds the readings readings. Let the top reading be the largest reading anywhere in the log.
Return how many stretches of neighbouring readings hold the top reading at least k times.
Example 1
The top reading is two and every reading is one. The stretches holding it at least twice are the two neighbouring pairs and the whole log.
Example 2
One reading is itself the top reading, and the single stretch holds it once.
Example 3
The top reading is two and the log holds only one of it, so no stretch can hold it twice.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_subarrays(readings: list[int], k: int) -> int:public long countSubarrays(int[] readings, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.