Degree of an Array
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
The **degree** of a non-empty array of non-negative integers is defined as the highest frequency of any single value within it. In other words, it is the count of the value that appears most often.
Given an integer array nums, find the length of the **shortest contiguous subarray** that has the **same degree** as nums itself.
Return that minimum length.
A subarray is a slice of consecutive elements. Note that there may be several values that all share the maximum frequency, so you should consider each of them and keep the smallest qualifying window.
Examples
Constraints
- `1 <= nums.length <= 50000`
- `0 <= nums[i] <= 49999`
- The array is guaranteed to contain at least one element.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.