by AskAI

Solutions:

Check these solutions from our community and artificial intelligence:
This solution is optimal because it is O(n) time complexity. However, it is not the most efficient solution. A more efficient solution would be to use a binary search, which would have a time complexity of O(log n).