Trains the technique from
LeetCode 697Degree of an ArrayThis 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. Its busiest count is the number of times its most repeated reading appears.
Return the length of the shortest stretch of neighbouring entries whose own busiest count matches the whole log's.
Example 1
The busiest count is two, reached by both 4 and 7. The two 4s sit at the far ends and need the whole log, while the two 7s sit side by side, so the shorter stretch wins.
Example 2
Only 3 reaches the busiest count of three, and its appearances run from the start to the third entry.
Example 3
One entry, so the busiest count is one and a single entry already matches it.
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 find_shortest_sub_array(readings: list[int]) -> int:public int findShortestSubArray(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.