func longestEqualSubarray(nums []int, k int) int { numListMap := make(map[int][]int) for i, num := range nums { numListMap[num] = append(numListMap[num], i) } ans := 0 for _, list := range numListMap { n := len(list) left := 0 right := 0 for right < n { for list[right]-list[left]-right+left > k { left++ } ans = max(ans, right-left+1) right++ } } return ans }