Longest Common Prefix

Easy · Arrays & Strings · about 10 minutes

Asked at Apple, Bloomberg, Google, Amazon, Microsoft, Meta, Samsung, Sony.

Find the longest leading piece shared by every string in strs. When the strings don't even agree on their first character, the answer is the empty string "".

Related guides