Given an array of strings, return the longest common prefix shared by all of them, or empty string if none.
Vertical scan works well: compare character i across every string until a mismatch. Horizontal reduce (prefix of first two, then with third, …) is equivalent.
Time O(S) where S is total characters. Watch empty array and early exit when the prefix shrinks to empty.
When you want live practice with follow-ups, try AI interview copilot.
Disclosure: I work on Linkjob AI.