Solution from Geeksforgeeks is confusing


This is another way of solving but looks more complex.

Brilliant solution and explanation from Coding Blocks

Yes there are many different ways to solve this problem. What is your question exactly ? And thanks for the appreciation.