type ints [][]int func (is ints) Len() int { return len(is) } func (is ints) Less(i, j int) bool { if is[i][0] == is[j][0] { return is[i][1] < is[j][1] } return is[i][0] > is[j][0] } func (is ints) Swap(i, j int) { is[i], is[j] = is[j], is[i] } func reconstructQueue(people [][]int) [][]int { sort.Sort(ints(people)) // Sort + insert n := len(people) for i := 0; i < n; i++ { if people[i][1] != i { tmp := people[i] copy(people[tmp[1]+1:i+1], people[tmp[1]:i]) people[tmp[1]] = tmp } } return people }