For this Question: Given an array of string words. Print all strings in words which is substring of another word in Lexicographic sorted order.

String words[i] is substring of words[j], if can be obtained removing some characters to left and/or right side of words[j].First- line contains an integer n which is the length of the array and the key string 'kstr', and the second line contains n strings of the array.

Constraints:
1<= n <= 1000
1<= str[i]. length <= 1000Print the array of answer in Lexicographic sorted order.Sample Input 1:
4
mass as hero superhero
Sample Output 1:
as hero 
Explanation 1:
"as" is substring of "mass" and "hero" is substring of "superhero".

Sample Input 2:
3
leetcode et code
Sample Output 2:
code et 
Explanation 2:
"et", "code" are substring of "leetcode"., I have written this Solution Code: import java.util.*;
import java.lang.*;

class Solution {
    public boolean search(String text, String pattern)
    {
        String concat = pattern + "$" + text;
        int l = concat.length();
        int Z[] = new int[l];
        getZarr(concat, Z);
        for(int i = 0; i < l; ++i){
            if(Z[i] == pattern.length()){
              return true;
            }
        }
        return false;
    }
    private void getZarr(String str, int[] Z) {
        int n = str.length();
        int L = 0, R = 0;
        for(int i = 1; i < n; ++i) {
            if(i > R){
                L = R = i;
                while(R < n && str.charAt(R - L) == str.charAt(R))
                    R++;
                Z[i] = R - L;
                R--;

            }else{
                int k = i - L;
                if(Z[k] < R - i + 1)
                    Z[i] = Z[k];
                else{
                    L = i;
                    while(R < n && str.charAt(R - L) == str.charAt(R))
                        R++;
                    Z[i] = R - L;
                    R--;
                }
            }
        }
    }

}

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        Solution solution = new Solution();
        int n=scanner.nextInt();
        String str[] = new String[n];
        List<String> ans = new ArrayList<String>();
        for(int i=0;i<n;i++)
            str[i]= scanner.next();
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i != j){
                    if(solution.search(str[j],str[i])){
                        ans.add(str[i]);
                        break;
                    }
                }
            }
        }
        Collections.sort(ans,(a, b) -> a.compareToIgnoreCase(b));
        for(String it:ans)
            System.out.print(it + " ");
        System.out.println();
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?