FastPrepValid Palindrome II

Valid Palindrome II

Bloomberg LP logoBloomberg LP● EasyFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Given a string s, return true if it can become a palindrome after deleting at most one character. Otherwise, return false.

Function

validPalindrome(s: String) → boolean

Examples

Example 1

s = "aba"return = true

The string is already a palindrome, so no deletion is needed.

Example 2

s = "abca"return = true

Deleting b or c leaves a palindrome.

Constraints

  • 1 <= s.length <= 10^5
  • s contains only lowercase English letters.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean validPalindrome(String s) {
    // write your code here
}
s"aba"
expectedtrue
Checking account…