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
Goal Parser Interpretation OverviewInput: "G()(al)"Decode each token:"G""G""()""o""(al)""al"Concatenate: "G" + "o" + "al"Output: "Goal"
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
Asked in
Amazon 15 Microsoft 12 Google 8
29.4K Views
Medium Frequency
~5 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen