Search
⌘K

Leetcode 14. Longest Common Prefix

Return the longest prefix string common to all strings in the array, or an empty string if none exists. The task reduces to comparing characters across all strings position-by-position up to the shortest string and stopping at the first mismatch.

Asked at:

Meta

Visa


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late April, 2025

Visa

Mid-level

Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".

Early January, 2025

Meta

Staff

Comments

Your account is free and you can post anonymously if you choose.