Practice Evaluate the Bracket Pairs of a String
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
knowledge contains distinct keys and their values. Replace every parenthesized key in s, including its parentheses, with its known value, or with ? when absent from knowledge. Parentheses do not nest and every enclosed key is nonempty. Preserve all text outside those pairs and return the result.
Source: Evaluate the Bracket Pairs of a String on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "(name)is(age)yearsold", knowledge = [["name","bob"],["age","two"]]
Output
"bobistwoyearsold"
# Example 2
Input
s = "hi(name)", knowledge = [["a","b"]]
Output
"hi?"
# Example 3
Input
s = "(a)(a)(a)aaa", knowledge = [["a","yes"]]
Output
"yesyesyesaaa"
Constraints
1 <= s.length <= 10^5
0 <= knowledge.length <= 10^5
knowledge[i].length == 2
1 <= keyi.length, valuei.length <= 10
s consists of lowercase English letters and round brackets '(' and ')'.
Every open bracket '(' in s will have a corresponding close bracket ')'.
The key in each bracket pair of s will be non-empty.
There will not be any nested bracket pairs in s.
keyi and valuei consist of lowercase English letters.
Each keyi in knowledge is unique.
Related LeetCode Problems
Practice more problems similar to Evaluate the Bracket Pairs of a String.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.