Bhaukkal answer hai;

interview-questions
Tags: #<Tag:0x00007f2426b6b6f0>

#1

public class Solution {
public String longestCommonPrefix(ArrayList A) {

    if(A.size()==0) return "";
    String prefix=A.get(0);
    
    for(int i=1;i<A.size();i++){
        while(A.get(i).indexOf(prefix) != 0){
            prefix=prefix.substring(0,prefix.length()-1);
        }
    }
    return prefix;
}

}