FastPrepShortest Suffix to Form a Palindrome

Shortest Suffix to Form a Palindrome

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Return the shortest string that can be appended to text so the result is a palindrome. If text is already a palindrome, return the empty string.

Function

shortestPalindromeSuffix(text: String) → String

Examples

Example 1

text = "banana"return = "b"

Appending b creates bananab.

Constraints

  • 0 <= text.length <= 2000.
  • The text contains lowercase English letters.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String shortestPalindromeSuffix(String text) {
  // Write your code here.
}
text"banana"
expected"b"
Checking account…