You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: d.go
    path of file: ./repos/codeforces-go/leetcode/weekly/359/d
    
    the code of the file until where you have to start completion: package main

// https://space.bilibili.com/206214
func longestEqualSubarray(nums []int, k int) (ans int) {
	pos := make([][]int, len(nums)+1)
	for i, x := range nums {
		pos[x] = append(pos[x], i-len(pos[x]))
	}
	for _, ps := range pos {
		left := 0
		for right, p := range ps {
			for p-ps[left] > k
    
func longestEqualSubarray(nums []int, k int) (ans int) {
	pos := make([][]int, len(nums)+1)
	for i, x := range nums {
		pos[x] = append(pos[x], i-len(pos[x]))
	}
	for _, ps := range pos {
		left := 0
		for right, p := range ps {
			for p-ps[left] > k {
				left++
			}
			ans = max(ans, right-left+1)
		}
	}
	return
}