Degree of an Array Problem

Degree of an Array Problem — ExecCode Easy DSA Practice

Solve the Degree of an Array problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

Examples

Input {"nums": [1, 2, 2, 3, 1]}; Output 2. Input {"nums": [1, 2, 2, 3, 1, 4, 2]}; Output 6

Constraints

nums.length will be between 1 and 50,000. nums[i] will be an integer between 0 and 49,999.

Practice Degree of an Array free on ExecCode. Browse DSA problems, topic map, and placement guides.