Amazon | OA | Reverse String in paranthesis
Anonymous User
1277

This question was asked in a 2020 online assessment:

Question
You are given a string that consists of lower case English letters and parenthesis.

Reverse the strings in each pair of matching parenthesis, starting from the innermost one.

Your result should not contain any parenthesis.

Example 1:

Input: s = "(abcd)"
Output: "dcba"

Example 2:

Input: s = "(oi(love)ew)"
Output: "weloveio"

Explanation: The substring "love" is reversed first, then the whole string is reversed.

Comments (3)