A CMS export lost the hyphens in its page slugs: dark-mode-toggle became darkmodetoggle. You have a dictionary of known words.
Write splitSlug(slug, dictionary) that returns every way to cut slug into pieces where every piece is a dictionary word. Write each way as the pieces joined with -.
Return the results sorted ascending by plain string comparison. Return [] if the slug can't be split. A dictionary word may be used any number of times.
Input: slug = "darkmodetoggle", dictionary = ["dark","mode","darkmode","toggle"] Output: ["dark-mode-toggle","darkmode-toggle"]
The first part can be dark then mode, or darkmode as one word. - sorts before letters.
Input: slug = "signin", dictionary = ["sign","in","sig","nin"] Output: ["sig-nin","sign-in"]
Both cuts use only dictionary words.
1 <= slug.length <= 200 <= dictionary.length <= 20dictionary are distinct.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 #291 Restore the Slug Hyphens. 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.