9. Palindrome Number

Palindrome Number (LeetCode 9) is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the String Manipulation Patterns pattern, in the Palindrome Check (Two Pointers / Reverse) subpattern.

How to solve Palindrome Number

Palindrome Number is a Palindrome Check problem, part of String Manipulation Patterns. Master palindrome checking using two pointers. Handle valid palindrome with alphanumeric and one removal cases.

Work towards the solution in these steps:

  1. Beware of overflow when you reverse the integer.

The reference solution runs in O(log_{10} n) time and O(1) space.

The Palindrome Number solution and editorial walks through the full approach with reference code.

Problem statement

Given an integer x, return true if x is a palindrome, and false otherwise.

Example 1:

Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left.

Example 2:

Input: x = -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.

Example 3:

Input: x = 10 Output: false Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

Constraints:

- -231 <= x <= 231 - 1

Follow up: Could you solve it without converting the integer to a string?

Topics and companies

Topics: Math.

Reported in interviews at Microsoft, Adobe, Bloomberg, Facebook, Google, Yahoo.

How to practise Palindrome Number on Thita.ai

Starter code is provided in C, C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(log_{10} n) time and O(1) space.

Open Palindrome Number in the code editor, or read the Palindrome Number editorial for a worked solution with its approach and complexity analysis.

Where Palindrome Number sits in the DSA pattern sheet

Problems related to Palindrome Number

Other problems that use the same Palindrome Check (Two Pointers / Reverse) and String Manipulation Patterns techniques:

Palindrome Number FAQ

What is the LeetCode number of Palindrome Number?

Palindrome Number is LeetCode problem 9, rated Easy.

What pattern is used to solve Palindrome Number?

Palindrome Number is a Palindrome Check problem. It belongs to the String Manipulation Patterns pattern, in the Palindrome Check (Two Pointers / Reverse) subpattern.

What is the time complexity of Palindrome Number?

The reference solution runs in O(log_{10} n) time and O(1) space.

Which companies ask Palindrome Number?

Palindrome Number has been reported in interviews at Microsoft, Adobe, Bloomberg, Facebook, Google, Yahoo.

Preparing this workspace.