FastPrepMinimum Deletions for a Non-Palindrome
Problems/Minimum Deletions for a Non-Palindrome

Minimum Deletions for a Non-Palindrome

Deloitte logoDeloitte● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Deloitte new grad online assessment. The report gives deletion as the operation and says the answer is zero for a string that is already not a palindrome. It leaves out the result for the impossible case and the exact limits on characters. We define those clearly. Our version is about 94% the same as the reported question.

You are given a non-empty lowercase string text. In one operation, you may delete any one character while preserving the relative order of all remaining characters.

Return the minimum number of deletions needed to make the remaining string a non-palindrome. If text is already a non-palindrome, return 0. If no sequence of deletions can produce a non-palindrome, return -1.

Strings of length zero or one are considered palindromes.

Function

minimumDeletionsForNonPalindrome(text: String) → int

Examples

Example 1

text = "abca"return = 0

abca is already different from its reverse, so no deletion is needed.

Example 2

text = "abba"return = 1

The original string is a palindrome. Deleting its first character produces bba, which is not a palindrome.

Example 3

text = "aaaa"return = -1

Every string obtainable by deletion contains only a characters, so every possible remainder is a palindrome.

Constraints

  • 1 <= text.length <= 100000
  • text contains only lowercase English letters.

More Deloitte Online Assessment questions

  • Seventh Nearest PalindromeOA · Seen May 2026
  • Minimum-Cost Solar Rooftop AllocationOA · Seen Jul 2025
  • Pair Elements with Even SumsOA · Seen Jul 2025
  • Count Divisible PermutationsOA · Seen Jan 2025
  • Largest Element in an ArrayOA · Seen Nov 2024
  • Install Carbon FiltersOA · Seen Oct 2023
  • Longest Substring with Even OccurrencesOA · Seen Oct 2023
  • Maximum Sum RectangleOA · Seen Apr 2022
  • Annual Bank Balance with Monthly Card FeesOA · Seen Jan 2022
  • Count Battleships by SizeOA · Seen Jan 2022

Similar questions at other companies

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Run-Length String CompressionSalesforce · OASalesforce interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
  • Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
  • Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
  • Lost MessagesSuperhuman · OASuperhuman interview questions
  • Reverse a StringFlexTrade · OAFlexTrade interview questions
  • Missing WordsVanguard · OAVanguard interview questions

Interview reports that mention this question

  • Deloitte New Grad Tech OA and Interview Questions: 14 Experiences
All Deloitte interview questionsSee Deloitte hiring insights
Saved
class Solution {
    public int minimumDeletionsForNonPalindrome(String text) {
        // Write your solution here.
    }
}
Checking account…