Ctrl K

Shared Start of Words

Easy
You are given an array of strings words. Find the longest string that **every** word in the array begins with. If the words do not even share their first letter, return the empty string "".
Example 1
words=['station', 'statue', 'status'] → 'stat'

All three words start with "stat" and then go their separate ways.

Example 2
words=['river', 'liver', 'rivet'] → ''

"liver" starts with a different letter, so there is no common start and the answer is the empty string.

Example 3
words=['code', 'co', 'coder'] → 'co'

The common start cannot be longer than the shortest word, "co".

Constraints
  • 1 ≤ len(words) ≤ 200
  • 0 ≤ len(words[i]) ≤ 200
  • words[i] consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDictionary Words in a Text EasyBookend Word Pairs EasyNo Number Starts Another EasySplit Into Dictionary Words MediumEvery Way to Space the Words Hard
loading Python…
Input
words=['station', 'statue', 'status']
Expected
'stat'

Run checks the first 3 tests in your browser. Submit checks all 151 tests on the server, hidden ones included.