Solution in Scala with all test cases running:
Class Solution {
def smallestNumber(arrayOfNumbers: Array[Int]) = {
val filteredSet = arrayOfNumbers.foldLeft(HashSet.empty[Int]){(acc, next)
=> if(next > 0) acc.+(next) else acc}
getSmallestNumber(filteredSet)
}
@tailrec
private def getSmallestNumber(setOfNumbers: HashSet[Int], index: Int = 1):
Int = {
setOfNumbers match {
case emptySet if(emptySet.isEmpty) => index
case set => if(!set.contains(index)) index else getSmallestNumber(set,
index + 1)
}
}
}