Reverse a number

Beginner Problems Basic Maths Easy
  • Fun Fact: Reversing the digits of a number is often used in designing certain algorithms and applications, such as in credit card number processing or generating unique access codes
  • This kind of problem strengthens understanding of basic manipulation and conversion of data types, especially in languages that treat strings and integers distinctly

You are given an integer n. Return the integer formed by placing the digits of n in reverse order.

Examples:

Input: n = 25

Output: 52

Explanation: Reverse of 25 is 52.

Input: n = 123

Output: 321

Explanation: Reverse of 123 is 321.

Input: n = 54

Constraints

  • 0 <= n <= 5000
  • n will contain no leading zeroes except when it is 0 itself.

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree