@@ -0,0 +1,2221 @@
+// Author: Param Singh %3Cparamsingh258@gmail.com%3E%0A// http://www.spoj.com/problems/PHONELST/%0A%0Aimport java.io.*;%0Aclass Trie %7B%0A    private class Node %7B%0A        Node children%5B%5D;%0A        boolean flag;%0A        Node() %7B%0A            children = new Node%5B10%5D;%0A            for (int i = 0; i %3C 10; i++)%0A                children%5Bi%5D = null;%0A            flag = false;%0A        %7D%0A    %7D%0A%0A    private Node root;%0A%0A    Trie() %7B%0A        root = new Node();%0A    %7D%0A%0A    private void insert(Node vertex, String s) %7B%0A        if (s.equals(%22%22)) %7B%0A            vertex.flag = true;%0A            return;%0A        %7D%0A        else %7B%0A            int next = s.charAt(0) - '0';%0A            if (vertex.children%5Bnext%5D == null) %7B%0A                vertex.children%5Bnext%5D = new Node();%0A            %7D%0A            insert(vertex.children%5Bnext%5D, s.substring(1, s.length()));%0A        %7D%0A    %7D%0A%0A    public void insert(String s) %7B%0A        insert(root, s);%0A    %7D%0A%0A    private boolean query(Node vertex, String s) %7B%0A        if (s.equals(%22%22)) %7B%0A            return false;%0A        %7D%0A        if (vertex.flag) %7B%0A            return true;%0A        %7D%0A        else %7B%0A            int c = s.charAt(0) - '0';%0A            return query(vertex.children%5Bc%5D, s.substring(1, s.length()));%0A        %7D%0A    %7D%0A%0A    public boolean query(String s) %7B%0A        return query(root, s);%0A    %7D%0A%7D%0A%0A%0Aclass PhoneLST %7B%0A        public static void main(String%5B%5D args) throws IOException %7B%0A        InputStreamReader isr = new InputStreamReader(System.in);%0A        BufferedReader in = new BufferedReader(isr);%0A        int t = Integer.parseInt(in.readLine());%0A        for (int term = 0; term %3C t; term++) %7B%0A            int n = Integer.parseInt(in.readLine());%0A            String a%5B%5D = new String%5Bn%5D;%0A            Trie tr = new Trie();%0A            int i;%0A            for (i = 0; i %3C n; i++) %7B%0A                a%5Bi%5D = in.readLine();%0A                tr.insert(a%5Bi%5D);%0A            %7D%0A            boolean flag = false;%0A            for (i = 0; i %3C n; i++) %7B%0A                if (tr.query(a%5Bi%5D)) %7B%0A                    flag = true;%0A                    break;%0A                %7D%0A            %7D%0A            if (flag)%0A                System.out.println(%22NO%22);%0A            else%0A                System.out.println(%22YES%22);%0A        %7D%0A    %7D%0A%7D%0A%0A%0A

Solve PHONELST for practice of tries