Reduce the string

Given a string A consisting of lowercase English alphabets. Reduce the string to its shortest length
by doing any number of operations (possibly zero).
In one operation selects a pair of adjacent letters in the string that match and deletes them.
For example the string bcaa is shortened to bc in one operation.

Find and return the string by reducing it to its shortest length. if the resultant string is empty return “empty”.



Input Format

The only argument given the string A.

Output Format

Return the string by reducing it to its shortest length. if the resultant string is empty return “empty”.

Constraints

1 <= length of the string <= 1000000

For Example

Input 1:
    A = "aaabccddd"
Output 1:
    "abd"

Input 2:
    A = baab
Output 2:
    "empty"
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Reduce the string on Interview Code Editor
Sign Up
to access hints and editorial solutions for Reduce the string

Discussion


Loading...
Click here to start solving coding interview questions