PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in string and numeric manipulation, specifically palindrome detection and generation of the next strictly larger numeric palindrome from a large integer represented as a string.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Check palindrome and find next larger palindrome

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem: Palindrome Check + Next Larger Palindrome ### Part 1: Palindrome validation Given a string `s`, determine whether `s` is a palindrome (reads the same forward and backward). - Return `true` if `s` is a palindrome, otherwise `false`. - Assume `s` contains only alphanumeric characters and is case-sensitive unless you explicitly normalize. ### Part 2: Next larger palindrome number Given a non-negative integer `x` (potentially very large), return the **smallest palindrome number strictly greater than `x`**. Because `x` may exceed 64-bit range, treat `x` as a string. ### Input/Output - **Input:** `s` (string) for Part 1; `x` (string representing a non-negative integer) for Part 2 - **Output:** boolean for Part 1; string for Part 2 ### Constraints (assume for interview) - `1 <= len(s) <= 2 * 10^5` - `1 <= len(x) <= 2 * 10^5` - `x` has no leading zeros unless `x == "0"` ### Examples **Part 1:** - `s = "racecar"` -> `true` - `s = "ab"` -> `false` **Part 2:** - `x = "123"` -> `"131"` - `x = "99"` -> `"101"` - `x = "808"` -> `"818"`

Quick Answer: This question evaluates proficiency in string and numeric manipulation, specifically palindrome detection and generation of the next strictly larger numeric palindrome from a large integer represented as a string.

Valid Palindrome (Case-Sensitive)

Given a string `s` consisting of alphanumeric characters, determine whether `s` is a palindrome — i.e. it reads the same forward and backward. Return `true` if `s` is a palindrome, otherwise `false`. Treat the comparison as **case-sensitive** (do not normalize case), so `"Aa"` is NOT a palindrome. **Examples** - `s = "racecar"` -> `true` - `s = "ab"` -> `false` - `s = "a"` -> `true` - `s = "abba"` -> `true`

Constraints

  • 1 <= len(s) <= 2 * 10^5
  • s contains only alphanumeric characters
  • Comparison is case-sensitive

Examples

Input: ("racecar",)

Expected Output: True

Explanation: Reads identically in both directions.

Input: ("ab",)

Expected Output: False

Explanation: 'ab' reversed is 'ba', which differs.

Input: ("a",)

Expected Output: True

Explanation: A single character is trivially a palindrome.

Input: ("abba",)

Expected Output: True

Explanation: Even-length palindrome.

Input: ("Aa",)

Expected Output: False

Explanation: Case-sensitive: 'A' != 'a', so not a palindrome.

Input: ("12321",)

Expected Output: True

Explanation: Numeric string that mirrors around the center '3'.

Input: ("abca",)

Expected Output: False

Explanation: First char 'a' matches last 'a', but 'b' != 'c'.

Hints

  1. A string is a palindrome iff it equals its own reverse.
  2. For O(1) extra space, walk two pointers from both ends toward the center and compare characters; stop at the first mismatch.
  3. Case-sensitive means 'A' != 'a' — do NOT lowercase before comparing.

Next Larger Palindrome Number (Big Integer)

Given a non-negative integer `x` represented as a **string** (because it may exceed 64-bit range), return the **smallest palindrome number strictly greater than `x`**, also as a string. The result must have no leading zeros. **Examples** - `x = "123"` -> `"131"` - `x = "99"` -> `"101"` - `x = "808"` -> `"818"` - `x = "9"` -> `"11"` - `x = "999"` -> `"1001"`

Constraints

  • 1 <= len(x) <= 2 * 10^5
  • x has no leading zeros unless x == "0"
  • x may exceed 64-bit range — process it as a string, never as a native integer

Examples

Input: ("123",)

Expected Output: "131"

Explanation: Mirror left '1','2' over -> '121'; not > 123, so bump middle 2->3 giving '131'.

Input: ("99",)

Expected Output: "101"

Explanation: All 9s overflow to a longer palindrome 101.

Input: ("808",)

Expected Output: "818"

Explanation: Mirror gives 808 (==x, not strictly greater); bump middle 0->1 -> 818.

Input: ("9",)

Expected Output: "11"

Explanation: Single all-9s digit rolls over to 11.

Input: ("0",)

Expected Output: "1"

Explanation: Mirror gives 0 (not > 0); bump middle 0->1 -> 1.

Input: ("1",)

Expected Output: "2"

Explanation: Smallest palindrome strictly greater than 1 is 2.

Input: ("11",)

Expected Output: "22"

Explanation: Mirror gives 11 (==x); bump to 22.

Input: ("19",)

Expected Output: "22"

Explanation: Mirror left '1' -> '11' which is < 19; increment with outward carry -> 22.

Input: ("1234",)

Expected Output: "1331"

Explanation: Mirror -> 1221 (< 1234); bump inner pair 2->3 -> 1331.

Input: ("129",)

Expected Output: "131"

Explanation: Mirror -> 121 (< 129); bump middle 2->3 -> 131.

Input: ("100",)

Expected Output: "101"

Explanation: Mirror -> 101 which is > 100, so it is the answer directly.

Input: ("999",)

Expected Output: "1001"

Explanation: All 9s overflow to 1001.

Input: ("12921",)

Expected Output: "13031"

Explanation: Mirror -> 12921 (==x); bump middle 9->10 carries outward: 12921 -> 13031.

Hints

  1. Mirror the left half of the digits onto the right half to form a candidate palindrome of the same length.
  2. If that mirrored candidate is strictly greater than x, it is the answer. Compare as equal-length strings (lexicographic == numeric here).
  3. Otherwise, increment the middle digit(s) by 1 and propagate the carry outward symmetrically, then the number is still a palindrome and is now larger.
  4. Special case: a string of all 9s (e.g. '9', '99', '999') rolls over to 1 followed by (n-1) zeros followed by 1 (e.g. '11', '101', '1001').
Last updated: Jun 21, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)