You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets.
Example 1
Input: s = (abcd)
Output: dcba
Explanation: A single group: the whole contents "abcd" is reversed to "dcba".
Example 2
Input: s = (u(love)i)
Output: iloveu
Explanation: Inner "love" reverses first, then the outer group reverses "uevoli" into "iloveu".
Example 3
Input: s = (mh(lg(tiro))a)
Output: algorithm
Explanation: Work from the innermost pair outward: "tiro" reverses to "orit", so the middle group "lg" + "orit" reverses to "tirogl". The outer group "mh" + "tirogl" + "a" reverses to "algorithm".
Keep a stack of character buffers; an opening bracket starts a new buffer, a closing bracket reverses the top buffer and folds it back into the one beneath — so the innermost brackets are always resolved first.
Run checks all cases above. Submit evaluates all test cases.