Longest Common Prefix
Strings
easy
Score: 10
Write a function to find the longest common prefix string amongst an array of strings strs of size n.
If there is no common prefix, return a string "null".
Input Format
First Parameter: Numbern
Second Parameter: An array of strings strs of size n
Output Format
Return a string
Example 1
Input:
3
flower flow flight
Output:
fl
Example 2
Input:
3
dog racecar car
Output:
null
Explanation: There is no common prefix among the input strings.
Constraints
1 <= n <= 2000 <= strs[i].length <= 200strs[i]consists of only lowercase English letters.- Expected Time Complexity -
O(n*m)wheremis the length of theans - Expected Space Complexity -
O(1)