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 "".
Explanation: There is no common prefix among the input strings.
1 <= strs.length <= 2000 <= strs[i].length <= 200strs[i] consists of only lowercase English letters if it is non-empty.This approach involves taking the first string in the array and comparing it with each subsequent string. For each comparison, the common prefix is updated. By the end of this systematic pairwise comparison of strings, we derive the overall longest common prefix.
This method works by checking each character position across all input strings, proceeding character by character. This approach terminates when a mismatch is found or when one string is exhausted.
The divide and conquer approach breaks the problem into smaller sub-problems. It recursively divides the array into two halves until it reduces to the smallest size, then it combines the results by finding a common prefix between two halves.
This approach uses binary search on the length of the common prefix. It checks a middle value to see if all strings have a common prefix of that length. If they do, the length is increased; otherwise, it is decreased, effectively narrowing down the range.