Back to problems

Insert Spaces Around Palindrome Layers

Algorithm · Walmart Labs · Easy

You are given a string s. Beginning with the full string, repeatedly compare the first character and the last character of the current substring. If they match, strip them away and record the first character as a separate token for the left side and the last character as a separate token for the right side. Continue this process on the newly created inner substring. When you encounter a pair of characters that are different, or the substring shrinks to a length of 1 or 0,…

Checking your access…