Swift version using functions rather than an iterative approach
'The solution obtained perfect score' - Codility
This solution uses functions rather than an iterative approach. So the solution relies heavily on the language's optimizations. A similar approach could be done in Java such as using Java's set operations and other functions.
public func solution(_ A : inout [Int]) -> Int {
let positives = A.filter{ $0 > 0}
let max = positives.count <= 100_000 ? positives.count + 1 : 100_001
return Set(1...max).subtracting(A).min() ?? -1
}
Note: The function declaration was from Codility and inout was unneeded. Returning an integer did not allow for nil so -1 was used.