Longest Common Prefix

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

Write a function to find the longest common prefix string among an array of strings. If there is no common prefix, return an empty string `""`. Indexing is **0-based**. Use **Vertical Scanning**: take the first string as the reference and scan column by column — the prefix ends at the first column where any string either runs out of characters or has a different character. **Example:** `["flower","flow","flight"]` → `"fl"` because columns 0 (`f`) and 1 (`l`) are shared by all strings, but column 2 fails (`"flight"[2] = 'i' ≠ 'o'`).

- `1 <= strs.length <= 200` - `0 <= strs[i].length <= 200` - `strs[i]` consists of only lowercase English letters.

Example 1: input strs = ["flower","flow","flight"]; output "fl". "fl" is the longest prefix shared by all three strings.

Example 2: input strs = ["dog","racecar","car"]; output "". There is no common prefix among the input strings.

Example 3: input strs = ["interspecies","interstellar","interstate"]; output "inters". The first 6 characters "inters" are shared by all strings.

Category: Strings. Topic: strings. Difficulty: Easy. Patterns: string-processing.