Goal Parser Interpretation - Problem
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order.
The Goal Parser will interpret:
"G"as the string"G""()"as the string"o""(al)"as the string"al"
The interpreted strings are then concatenated in the original order.
Given the string command, return the Goal Parser's interpretation of command.
Input & Output
Example 1 — Basic Mixed Command
$
Input:
command = "G()(al)"
›
Output:
"Goal"
💡 Note:
G stays G, () becomes o, (al) becomes al. Concatenated: G + o + al = "Goal"
Example 2 — Multiple Patterns
$
Input:
command = "G()()()()(al)"
›
Output:
"Goooal"
💡 Note:
G stays G, each () becomes o (4 times), (al) becomes al. Result: G + o + o + o + o + al = "Goooal"
Example 3 — Only Parentheses
$
Input:
command = "(al)G(al)()()G"
›
Output:
"alGalooG"
💡 Note:
(al)→al, G→G, (al)→al, ()→o, ()→o, G→G. Concatenated: "alGalooG"
Constraints
- 1 ≤ command.length ≤ 100
- command consists of "G", "()", and/or "(al)" in some order
Visualization
Tap to expand
Understanding the Visualization
1
Input Command
String with G, (), and (al) tokens
2
Token Mapping
G→G, ()→o, (al)→al
3
Concatenate
Join decoded tokens into final string
Key Takeaway
🎯 Key Insight: Simple token replacement - scan and decode each pattern G, (), (al) then concatenate
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code