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. A template can be a whole HTML email, up to 300,000 characters long.
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 <= 3 * 10^5{ or }.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, 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.