Approach Used : Code (C++) Time Complexity: O(n): Space Complexity: O(1): no extra space is used. Connect With Me :