Middle+
Implement a function that takes []any and delta int. It should increase only the first occurrences of unique integers by delta. Other types and repeated numbers should remain unchanged. The function should return the updated slice and two numbers: - updated — how many unique numbers were changed, - duplicates — how many numeric elements turned out to be duplicates func IncrementUniqueIntsInMixed(xs []any, delta int) ([]any, int, int) { // your code }.
sobes.tech AI
Answer from AI
go func IncrementUniqueIntsInMixed(xs []any, delta int) ([]any, int, int) { seen := make(map[int]bool) updated := 0 duplicates := 0
for i, v := range xs {
val, ok := v.(int)
if !ok {
// not a number, skip
continue
}
if !seen[val] {
// first occurrence of a unique number — increment
xs[i] = val + delta
seen[val] = true
updated++
} else {
// repeated number — count as duplicate
dublicates++
}
}
return xs, updated, duplicates
}