The following algorithm can be used to encode a sequence of characters s:
- Find any palindrome of even length in s. A palindrome is a string that reads the same forward and backward. If there are no palindromes of even length, go to step 3.
- Remove the last half of the selected palindrome from s. For example, if the palindrome is "0110", remove the "10". Go to step 1.
- Print the remaining sequence of characters.
Note that the resulting sequence is not necessarily unique since there may be multiple palindromes to choose from in step 1.
Given a String s containing only the digits '0' and '1', return the length of the shortest possible string that can result from applying the above algorithm to s.
|