PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates proficiency in numeric and string manipulation, algorithmic thinking, and edge-case reasoning related to palindromic number generation.

  • Uber
  • Coding & Algorithms
  • Data Scientist

Find the Next Larger Palindrome

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Interview Round: Onsite

Given a positive integer `n`, return the smallest integer strictly greater than `n` whose decimal representation is a palindrome. A palindrome reads the same from left to right and right to left. Do not allow leading zeros. Examples: - `n = 9` -> `11` - `n = 123` -> `131` - `n = 808` -> `818` - `n = 999` -> `1001` Discuss edge cases such as single-digit inputs, numbers consisting only of `9`s, even versus odd digit lengths, and inputs that are already palindromes.

Quick Answer: This question evaluates proficiency in numeric and string manipulation, algorithmic thinking, and edge-case reasoning related to palindromic number generation.

Given a positive integer `n`, return the smallest integer strictly greater than `n` whose decimal representation is a palindrome. A palindrome reads the same from left to right and right to left. The result must not contain leading zeros. Examples: - `9 -> 11` - `123 -> 131` - `808 -> 818` - `999 -> 1001` Be careful with edge cases such as single-digit inputs, numbers made entirely of `9`s, even versus odd digit lengths, and inputs that are already palindromes. A brute-force approach that checks every number after `n` is not efficient enough; instead, reason about how palindromes are formed.

Constraints

  • 1 <= n < 10^18
  • The returned palindrome must have no leading zeros

Examples

Input: (1,)

Expected Output: 2

Explanation: The next integer after 1 is 2, and every single-digit number is a palindrome.

Input: (9,)

Expected Output: 11

Explanation: After 9, the next palindrome is 11.

Input: (123,)

Expected Output: 131

Explanation: Mirroring gives 121, which is too small, so the middle is increased to produce 131.

Input: (808,)

Expected Output: 818

Explanation: 808 is already a palindrome, but the answer must be strictly larger, so the next one is 818.

Input: (1221,)

Expected Output: 1331

Explanation: 1221 is a palindrome with even length. The next larger palindrome is obtained by increasing the middle pair.

Input: (12932,)

Expected Output: 13031

Explanation: Mirroring gives 12921, which is too small. Incrementing the middle with carry leads to 13031.

Input: (999,)

Expected Output: 1001

Explanation: For numbers consisting only of 9s, the next palindrome has one more digit: 1001.

Hints

  1. Try building a palindrome by copying the left half of the number onto the right half.
  2. If that mirrored number is not strictly greater than `n`, increment the middle digit(s) and mirror again. Numbers like 9, 99, and 999 need special handling.
Last updated: May 11, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Minesweeper and Word Search - Uber (medium)
  • Implement Store Autocomplete - Uber (medium)
  • Implement Cache Eviction And Seat Assignment - Uber (medium)
  • Schedule Non-Overlapping Meetings Efficiently - Uber (hard)
  • Evaluate an Arithmetic Expression - Uber