A bundler numbers the files of a project from 0 to n - 1. Each pair imports[i] = [a, b] means file a imports file b.
Write importMap(n, imports) that returns an array of n lists, where list i holds every file that file i imports, sorted ascending. A file that imports nothing gets an empty list.
No pair appears twice and no file imports itself.
Input: n = 4, imports = [[0,2],[0,1],[2,3],[1,3]] Output: [[1,2],[3],[3],[]]
File 0 imports 2 and 1, listed sorted as [1, 2]. File 3 imports nothing.
Input: n = 3, imports = [[2,0]] Output: [[],[],[0]]
Only file 2 imports anything. Imports go one way, so file 0's list stays empty.
1 <= n <= 100000 <= imports.length <= 500000 <= a, b < n and a !== bRun 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 #404 Build an Import Map. 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.