A theme system loads a list of stylesheets, given by name in sheets. Each rule in rules is a pair [first, second] meaning stylesheet first must load before second, so that second can override it.
Write loadOrder(sheets, rules) that returns every stylesheet name in a valid load order. Whenever several stylesheets are ready to load, take the one whose name comes first in plain string order (the order sort() uses). If the rules contain a circle, return [].
Input: sheets = ["reset.css","base.css","theme.css","app.css"], rules = [["reset.css","base.css"],["base.css","app.css"],["theme.css","app.css"]] Output: ["reset.css","base.css","theme.css","app.css"]
reset.css and theme.css are ready first, and reset.css sorts first. That frees base.css, which sorts before theme.css. app.css waits for both.
Input: sheets = ["a.css","b.css"], rules = [["a.css","b.css"],["b.css","a.css"]] Output: []
Each must load before the other, which is impossible.
1 <= sheets.length <= 5 * 10^40 <= rules.length <= 10^5rules is in sheets.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 #441 Stylesheet Load Order. 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.