Longest common prefix of a list of strings
Coding problemEasyAsked in: Google, Microsoft, VMware
Given a list of strings, return the longest text that every string in the list starts with. If they share no first character, or the list is empty, return an empty string.
Comparison is exact: upper and lower case are different characters, and spaces count.
Examples
Example 1
Input: words = ["flower","flow","flight"]
Output: "fl"
Example 2
Input: words = ["dog","racecar","car"]
Output: ""
Example 3
Input: words = ["interview","internet","interval"]
Output: "inter"
Constraints
- The list holds between 0 and 1,000 strings
- Each string has between 0 and 1,000 printable ASCII characters
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.