by AskAI

Solutions:

Check these solutions from our community and artificial intelligence:
The candidate's solution is correct and solves the problem. The approach is straightforward and easy to understand. The time complexity of the solution is O(n) and the space complexity is O(1).