For this Question: Given an array of N strings, find the longest common prefix among all strings present in the array.The fist line of each test contains a single integer N. Next line has space-separated N strings.

Constraints:-
1 <= N <= 10^3
1 <= |S| <= 10^3
Print the longest common prefix as a string in the given array. If no such prefix exists print "-1"(without quotes).Sample Input:
4
geeksforgeeks geeks geek geezer

Sample Output:
gee

Sampel Input:-
3
a b c

Sample Output:-
-1, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] str = br.readLine().split(" ");
        String ref = str[0];
        for(String s: str){
            if(s.length()<ref.length()){
                ref = s;
            }
        }

        for(int i=0; i<n; i++){
            if(str[i].contains(ref) == false){
                ref = ref.substring(0, ref.length()-1);
            }
        }
        if(ref.length()>0)
            System.out.println(ref);
        else
            System.out.println(-1);
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?