In this video, we will learn how to reverse a number using Python. We have divided this video into 4 parts.
Below is the list of approaches that we will cover in this video:
1. What is the prime number?
2. Iterative method to reverse a number
3. Recursive method to reverse a number
4. Inbuilt method to reverse a number
5. Using the stack method to reverse a number.
Reversing a number is a technique to reverse any number, i.e. 12345's reverse form will be 54321.
1. Iterative method to reverse a number: In this method, we will use a loop to reverse our number.
Time complexity will be: O(n), and Auxiliary Space: O(1).
2. Recursive method to reverse a number: In this method, we will use recursion to reverse our given number.
Time complexity will be: O(log(n)), and Auxiliary Space: O(log(n)).
3. Inbuilt method to reverse a number: In this method, we will use in build reverse() method, concatenation method, and Access List (lis [::]) method.
4. Using the stack method: In this method, we will use the stack, we will first push all the elements into the stack and then we will pop all the elements, as we know that stack works on LIFO the result we will get will be a reverse number.
Program to reverse digits of a number: https://www.geeksforgeeks.org/write-a-program-to-reverse-digits-of-a-number/