My solution in Swift, I check if the array is not empty and bigger than two elements :
func minMinMax(array: [Int]) -> [Int] { guard !array.isEmpty, array.count > 2, let min = array.min(), let max = array.max(), let minimumAbsent = ((min...max).first{!array.contains($0)}) else { return [] } return [min, minimumAbsent, max] }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in Swift, I check if the array is not empty and bigger than two elements :