FunctionRacerProblemsRace

Degree of an Array

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

The degree of a list is the highest number of times any single value appears in it.

Find the shortest contiguous stretch of nums that has the same degree as the whole list, and return its length.

Example 1

nums [1,2,2,3,1]
returns 2

Degree is 2 (both 1 and 2). The stretch [2, 2] has length 2 and degree 2.

Example 2

nums [1,2,2,3,1,4,2]
returns 6

2 appears 3 times, first at index 1 and last at index 6: length 6.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems