#53 · Strings · Intermediate · 55 XP · about 8 min
Write common_prefix(words) that returns the longest string that every word in words starts with. When the words do not even share their first letter, or the list is empty, return an empty string.
common_prefix(["interview", "internet", "interval", "internal"]) # returns 'inter' common_prefix(["dog", "dot", "door"]) # returns 'do' common_prefix(["dog", "cat", "cow"]) # returns ''
words has 0 to 1,000 items.Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.