Skip to main content
LeetCode 697, Easy. Topics: Array, Hash Table. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 40 parametrized pytest cases, and a playground notebook:

Problem

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

Constraints

  • 1 <= nums.length <= 5 * 10^4
  • 0 <= nums[i] <= 5 * 10^4

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026