top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Palindrome Integer InterviewBit Solution

Sep 6, 2020
1 min read

Updated: Sep 18, 2020


Problem Description:

Determine whether an integer is a palindrome. Do this without extra space.

A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed. Negative numbers are not palindromic.


Example :

Input : 12121 
Output : True  
Input : 123 
Output : False


Approach


The approach is straight forward, we just convert the given number into a string, and then can check whether the string is palindrome or not.

Another method could be that we can store this number to another number and then reverse one of them.



Time & Space Complexity:

Time Complexity: O(N), N is the number of digits in given number
Space Complexity: O(1)



Solution:


Code in C++


1 Comment


AliceHughes
3 days ago

Reading this at https://nouveaucasinos.com, I couldn't help noticing that converting the integer to a string technically uses extra space, which seems to contradict the problem's "without extra space" constraint. In an interview, I'd probably go with reversing just half the number to avoid overflow and stay within O(1) space, even though the negative check is straightforward.

Like
bottom of page