Given the array of strings S, write a program to find the longest common prefix string which is the prefix of all the strings in the array.

Problem Note

  • The longest common prefix for a pair of strings S1 and S2 is the longest string which is the prefix of both S1 and S2.
  • All given inputs are in lowercase letters a-z.
  • If there is no common prefix, return "-1".

Example 1

Input: S[] = [“apple", "ape", "april”] 
Output: "ap"

Example 2

Input: S[] = ["flower","flow","flight"] 
Output: "fl" 

Example 3

Input: S[] = [“after”, ”academy, ”mindorks”] 
Output: “-1” 
Explanation: There is no common prefix among the input strings.