How to find the missing values in a sorted range (x to y) array with Swift

1 Answer

0 votes
import Foundation

let x = 4
let y = 15
let arr = [5, 5, 5, 5, 6, 7, 9, 10, 10, 10, 11, 13]

let range = Set(x...y)
let arrSet = Set(arr)
let missingValues = range.subtracting(arrSet)

print("missingValues:", missingValues)



/*
run:
   
missingValues: [12, 8, 15, 4, 14]

*/

 



answered Oct 27, 2024 by avibootz
...