We will solve this problem with 2 pointer approach first and after that we will optimize solution by just using 1 pointer.
Time complexity of both solutions : O(n) where n is length of input array
Space complexity of both solutions : O(1) i.e constant as we havent use any extra space.