As reported: Apple Java backend engineer (SDE 2, Hyderabad, 2025), round 1 coding: longest common prefix, after merge two sorted arrays and top K frequent elements; two approaches were expected for each, with one coded when asked.
Return the longest common prefix of an array of strings. If there is none, return "".
This is LeetCode 14 — Longest Common Prefix.
Example 1
strs = ["flower","flow","flight"] -> "fl"
Example 2
strs = ["dog","racecar","car"] -> ""
Constraints: 1 ≤ strs.length ≤ 200; 0 ≤ strs[i].length ≤ 200; lowercase English letters.
Code runner format: one JSON value per line: strs (LeetCode's test-case format). Implement longestCommonPrefix(strs); the harness prints the prefix.