Longest Common Prefix

Find the longest common prefix string amongst an array of strings.

Medium12/15/2023

Problem statement

Write a program that takes an array of lowercase strings and returns the longest common prefix (LCP) that is shared amongst all strings. If there is no common prefix, return an empty string. The words are separated by a space character.

Problem leaderboard

#
Size
%
Users
#1
32 c.
Top 6%
voytxt
#2
36 c.
Top 17%
oskar
Natanaelel
#3
37 c.
Top 33%
randolchance
tree
Steffan
#4
38 c.
Top 39%
scpchicken
#5
39 c.
Top 44%
Thomasdcrt
#6
71 c.
Top 50%
Shanethegamer
#7
75 c.
Top 56%
alexisab
#8
77 c.
Top 61%
maximec-indy
#9
79 c.
Top 72%
AlephSquirrel
mathis
#10
81 c.
Top 78%
davyboyh
#11
84 c.
Top 89%
Pascal
rucin93
#12
99 c.
Top 94%
CGjupoulton
#13
150 c.
Top 100%
cabz0r