The current implementation is binary search in its most basic form. It can be generalized to take the range and a function (f) with boolean return value as arguments and return the smallest value in the range that when passed into the function (f) returns true. This generalization will help in its application to all use cases. The same enhancement can be applied to other algorithms. Will be happy to discuss the approach/implementation further.