leetle

Daily challenge for 2026-04-03

458. Frequent Value Distance Gap

Given an array of integers nums, find the maximum distance between any two occurrences of the same value, but only for values that appear exactly twice in the array. If no value appears exactly twice, return -1.

Example:
Input: nums = [1, 2, 3, 2, 4, 1, 5]
Output: 5
Explanation: 1 appears twice at indices 0 and 5 (distance 5). 2 appears twice at indices 1 and 3 (distance 2). The maximum is 5.

Run this challenge interactively in Python or JavaScript when the app loads.