A CSS class linter reads a long class string text with the spaces stripped out and tries to cover it with known utility class names from words. Pieces must not overlap, each word may be used many times, and characters not covered by any word are leftovers.
Write fewestLeftovers(text, words) that returns the smallest possible number of leftover characters.
Input: text = "navbarxlink", words = ["nav","bar","link","navbar"] Output: 1
navbar + x + link: only the x is left over.
Input: text = "abc", words = ["d"] Output: 3
No word appears, so every character is left over.
1 <= text.length <= 10001 <= words.length <= 1001 <= words[i].length <= 30Run 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 #551 Fewest Leftover Characters. 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.