You are given a string s.
Consider performing the following operation until s becomes empty:
For example, let initially s = "aabcbbca". We do the following operations:
Return the value of the string s right before applying the last operation. In the example above, answer is "ba".
Examples
Example 1
Input: s = "aabcbbca"
Output: "ba"
Explanation: Explained in the statement.
Example 2
Input: s = "abcd"
Output: "abcd"
Explanation: We do the following operation:
- Remove the underlined characters s = "abcd". The resulting string is s = "".
The string just before the last operation is "abcd".
Constraints
1 <= s.length <= 5 * 105
s consists only of lowercase English letters.
3039. Apply Operations to Make String Empty
Medium
30 Points
Array
Hash Table
Sorting
Counting
You are given a string s.
Consider performing the following operation until s becomes empty:
For example, let initially s = "aabcbbca". We do the following operations:
Return the value of the string s right before applying the last operation. In the example above, answer is "ba".
Examples
Example 1
Input: s = "aabcbbca"
Output: "ba"
Explanation: Explained in the statement.
Example 2
Input: s = "abcd"
Output: "abcd"
Explanation: We do the following operation:
- Remove the underlined characters s = "abcd". The resulting string is s = "".
The string just before the last operation is "abcd".
Constraints
1 <= s.length <= 5 * 105
s consists only of lowercase English letters.
Apply Operations to Make String Empty - Practice Coding | SlaveCode