Regarding extra space

In the problem description its mention that we cant use extra space. So does that mean we cant use integer variable for storing previous value or we can use it?

Hey I suggest you learn about space complexity and time complexity.

Space Complexity : How your space increases as your input to the program becomes exponential and similar definition would work for time as well.

Constant space or no extra space : O(1)

In a nutshell : you are allowed to use as many variables as you want to solve problem.


Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.