FastPrepShortest Subarray With the Full Degree

Shortest Subarray With the Full Degree

Agoda logoAgoda● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

The degree of an array is the largest frequency of any value. Return the length of the shortest contiguous subarray having the same degree as nums.

Function

findShortestSubarray(nums: int[]) → int

Examples

Example 1

nums = [1,2,2,3,1]return = 2

Case 1 exercises the documented deterministic contract.

Example 2

nums = [1,2,2,3,1,4,2]return = 6

Case 2 exercises the documented deterministic contract.

Example 3

nums = [1]return = 1

Case 3 exercises the documented deterministic contract.

Constraints

  • 1 <= nums.length <= 200000.
  • -10^9 <= nums[i] <= 10^9.

More Agoda problems

See Agoda hiring insights
public int findShortestSubarray(int[] nums) {
    // Write your code here.
}
nums[1,2,2,3,1]
expected2
Checking account…