Super Reduced String

Super Reduced String

Steve has a string, , consisting of  lowercase English alphabetic letters. In one operation, he can delete any pair of adjacent letters with same value. For example, string “aabcc” would become either “aab” or “bcc” after operation.
Steve wants to reduce  as much as possible. To do this, he will repeat the above operation as many times as it can be performed. Help Steve out by finding and printing ‘s non-reducible form!
Note: If the final string is empty, print Empty String .
Input Format
A single string, .
Constraints
Output Format
If the final string is empty, print Empty String; otherwise, print the final non-reducible string.
Sample Input 0

Sample Output 0

Sample Case 0
Steve can perform the following sequence of operations to get the final string:
  1. aaabccddd → abccddd
  2. abccddd → abddd
  3. abddd → abd
Thus, we print abd.
Sample Input 1

Sample Output 1

Explanation 1
Steve can perform the following sequence of operations to get the final string:
  1. baab → bb
  2. bb → Empty String
Thus, we print Empty String.
Sample Input 2

Sample Output 2

Explanation 2
Steve can perform the following sequence of operations to get the final string:
  1. aa → Empty String

Thus, we print Empty String.

Code:

Add a Comment

Your email address will not be published. Required fields are marked *