A bundler wants to find assets with identical contents so it can ship them once. Each entry of listing describes one folder: the folder path, then one or more files written as name(content), all separated by single spaces. For example, "public logo.svg(abc) icon.svg(xyz)" means public/logo.svg holds abc and public/icon.svg holds xyz.
Write duplicateFiles(listing) that returns groups of full paths (folder + "/" + name) whose contents are identical, keeping only groups with at least two files.
Order the groups by where their content first appears in the listing (reading entries in order, files left to right), and list the paths inside each group in that same reading order.
Input: listing = ["assets/img logo.svg(abc) icon.svg(xyz)","public logo.svg(abc)","src app.js(xyz) util.js(qq)"] Output: [["assets/img/logo.svg","public/logo.svg"],["assets/img/icon.svg","src/app.js"]]
abc appears in two files, then xyz in two. qq appears once, so it's left out.
Input: listing = ["root a.txt(1) b.txt(2)"] Output: []
No two files share contents.
0 <= listing.length <= 1000Run 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 #36 Duplicate Asset Contents. 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.