Longest Common Prefix
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an array of strings words, return the longest string that is a prefix shared by **every** string in the array.
A *prefix* is a leading run of characters. For example, "co" and "cod" are both prefixes of "code", but "ode" is not. The longest common prefix must appear at the start of every word, character for character, in the same positions.
If the strings share no common starting characters, return the empty string "".
Comparisons are case-sensitive, so "Go" and "go" do not share the prefix "go".
Examples
Constraints
- `1 <= words.length <= 200`
- `0 <= words[i].length <= 200`
- Each `words[i]` consists only of lowercase and uppercase English letters.
- An empty string in the input forces the answer to be `""`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.