FastPrepShortest Subarray With the Full Degree
Problems/Shortest Subarray With the Full Degree

Shortest Subarray With the Full Degree

Agoda logoAgoda● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

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

  • Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Can Place FlowersPHONE SCREEN · Seen Nov 2026
  • Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
All Agoda interview questionsSee Agoda hiring insights
Saved
class Solution {
    public int findShortestSubarray(int[] nums) {
        // Write your code here.
    }

}
Checking account…