A refactoring tool wants to suggest a common folder for a group of import paths. As a first step, it needs the longest string that every path starts with.
Write sharedStart(paths) that returns the longest common prefix of all strings in paths (it may end in the middle of a folder name). If paths is empty, or the strings share no first character, return "".
Input: paths = ["src/ui/button.js","src/ui/badge.js","src/utils.js"] Output: "src/u"
All three start with src/u; the next characters are i, i, and t.
Input: paths = ["lib/a.js","src/a.js"] Output: ""
The first characters already differ.
0 <= paths.length <= 2000 <= paths[i].length <= 200Run 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 #367 Shared Start of Import Paths. 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.