FastPrepPalindrome with One Deletion

Palindrome with One Deletion

WhatNot logoWhatNot● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

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

A palindrome reads the same from left to right and right to left. Keeping the string unchanged is allowed.

Function

validPalindrome(s: String) → boolean

Examples

Example 1

s = "abca"return = true

Deleting b gives aca; deleting c gives aba.

Example 2

s = "abc"return = false

Each possible single deletion leaves two different characters.

Example 3

s = "aba"return = true

The string is already a palindrome; no deletion is required.

Constraints

  • 1 <= s.length <= 10000.
  • s contains only lowercase English letters.

More WhatNot problems

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