A notification service stores messages as templates like Hi {{ name }}, you have {{count}} new messages. Before filling them in, it splits each template into tokens.
Write tokenizeTemplate(template) that returns a list of tokens in order. Plain text becomes ["text", content]. Each {{ ... }} becomes ["var", name], where name is the text between the braces with surrounding spaces trimmed.
If a {{ has no matching }} after it, everything from the last token's end to the end of the template is plain text. Never output empty text tokens.
Input: template = "Hi {{ name }}, you have {{count}} new messages" Output: [["text","Hi "],["var","name"],["text",", you have "],["var","count"],["text"," new messages"]]
Two variables split the text into three pieces.
Input: template = "{{a}}{{b}}" Output: [["var","a"],["var","b"]]
No text between or around the variables, so no text tokens.
0 <= template.length <= 10^4{ or }.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #628 Tokenize a Message Template. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.