Space complexity

Will you tell me that I am also doing this question in space O(1) with this approach mentioned in the link.

yes shreyansh,
Your code is using O(1) space.
Please let me know if there is any other doubt.