Skip to interview prep
Apexed

32. Longest Common Prefix

EasyString algorithms

Return the longest string that is a prefix of every string in words, or an empty string if there is none.

Example 1

Input: words = ["flower", "flow", "flight"]
Output: "fl"

Constraints

  • 1 ≤ words.length ≤ 200
  • 0 ≤ words[i].length ≤ 200

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Longest Common Prefix — coding interview practice — Apexed