What is the advantage of thie approach?

Any advantage other than avoiding the extra memory allocation?

@PoojaSingh22,
It is simple to understand and implement and we can make any changes according to the question’s requirements.