Mark As Completed Discussion

Good morning! Here's our prompt for today.

We have a string str like the following:

JAVASCRIPT
1const str = "bubble";

Find a way to convert it to a palindrome by inserting characters in front of it. Recall that a palindrome is defined as "a word, phrase, or sequence that reads the same backward as forward".

Description

What's the shortest palindrome that can be returned? For example, the following above string should return:

JAVASCRIPT
1shortestPalindrome("bubble")
2// "elbbubble"

Constraints

  • Length of the given string <= 1000
  • The string can contain any ASCII letters
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

We'll now take you through what you need to know.

How do I use this guide?