PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Check near-palindrome with one deletion states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Check near-palindrome with one deletion

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a string s, determine whether it can become a palindrome after deleting at most one character. Return both the boolean result and one valid index to delete if possible. Provide an O(n) two-pointer solution and discuss how you would handle Unicode or case-insensitive comparisons.

Quick Answer: This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Check near-palindrome with one deletion states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Given a string `s`, determine whether it can become a palindrome after deleting **at most one** character. Return a pair `[result, index]`: - `result` is a boolean: `true` if `s` is already a palindrome or can be made one by deleting a single character, otherwise `false`. - `index` is one valid 0-based index you could delete to make `s` a palindrome. If `s` is already a palindrome (no deletion needed) or no single deletion works, return `-1` for the index. Use the classic two-pointer scan: walk inward from both ends; on the first mismatch, the only two candidates are deleting the left or the right character, so check whether either resulting substring is a palindrome. This runs in O(n) time and O(1) extra space. Follow-up to discuss (not graded here): for Unicode you should normalize (e.g. NFC) and iterate over code points / grapheme clusters rather than UTF-16 code units; for case-insensitive comparison, casefold the string first — both are preprocessing steps that keep the core two-pointer logic unchanged.

Constraints

  • 0 <= len(s) <= 10^5
  • s consists of lowercase (or arbitrary) characters
  • An empty string and a single-character string are palindromes (return [True, -1])
  • If s is already a palindrome, the deletion index is -1 (no deletion needed)

Examples

Input: ("aba",)

Expected Output: [True, -1]

Explanation: Already a palindrome, so no deletion is needed; index is -1.

Input: ("abca",)

Expected Output: [True, 1]

Explanation: First mismatch at b vs c; deleting index 1 ('b') leaves 'aca', a palindrome.

Input: ("abc",)

Expected Output: [False, -1]

Explanation: a vs c mismatch; neither 'bc' nor 'ab' is a palindrome, so one deletion is not enough.

Input: ("",)

Expected Output: [True, -1]

Explanation: Empty string is trivially a palindrome.

Input: ("a",)

Expected Output: [True, -1]

Explanation: Single character is a palindrome.

Input: ("deeee",)

Expected Output: [True, 0]

Explanation: d vs e mismatch at the ends; deleting index 0 ('d') leaves 'eeee', a palindrome.

Input: ("racecar",)

Expected Output: [True, -1]

Explanation: Already a palindrome; index is -1.

Input: ("abcdba",)

Expected Output: [True, 2]

Explanation: Outer pairs match down to c vs d; deleting index 2 ('c') leaves 'abdba', a palindrome.

Input: ("abcde",)

Expected Output: [False, -1]

Explanation: a vs e mismatch; neither 'bcde' nor 'abcd' is a palindrome, so it cannot be fixed with one deletion.

Hints

  1. Use two pointers from both ends. As long as characters match, move inward.
  2. At the first mismatch, only two repairs are possible: delete the left character or delete the right one. Check if either remaining substring is a palindrome.
  3. If you reach the middle with no mismatch, the string was already a palindrome — return -1 for the index. If both repair attempts fail, it's impossible.
Last updated: Jun 26, 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

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)