package two import ( "math" "slices" ) func checkWithComparator(nums []int, comparator comparator, count int) bool { if count > 1 { return false } for i := 1; i < len(nums); i++ { if comparator(nums, i) || !isSafe(nums[i-1], nums[i]) { count++ removeFirst, removeSecond := nextLevels(nums, i) return checkWithComparator(removeFirst, comparator, count) || checkWithComparator(removeSecond, comparator, count) } } return true } func isSafe(m, n int) bool { return int(math.Abs(float64(m-n))) <= 3 } func nextLevels(nums []int, i int) ([]int, []int) { first, second := slices.Clone(nums), slices.Clone(nums) return append(first[:i-1], first[i:]...), append(second[:i], second[i+1:]...) }