Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Reverse an Integer
00:00
5 left

Reverse an Integer

EasyPython

Problem

Reverse an integer in a programming language of your choice. Implement reverse_integer(x) to return the digits of integer x in reverse order, preserving its sign. For example, 123 returns 321, -456 returns -654, and 1200 returns 21; assume x is a valid integer.

Constraints

  • x is an integer
  • The result uses standard integer representation
  • The sign of x must be preserved
  • Leading zeros in the reversed result are discarded

Function Signature

def reverse_integer(x):
Interviewer

Your question is Reverse an Integer. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.