In this problem you are given input of phone numbers and you are supposed to determine whether any number is the prefix of another. I have an addchild method that returns true or false if a given string can be inserted and is not a prefix of another string. How could I improve the efficiency of my code so that I could pass the time constraints?http://www.spoj.com/problems/PHONELST/import java.util.Arrays;import java.util.Scanner;class PhoneList {static class Node{    Node [] children;    int value;    public Node(){        children=new Node[11];    }    public Node(int value){        children=new Node[11];        this.value=value;    }}static class  Trie{    Node root=null;    public Trie(){        root=new Node();    }    boolean addChild(String s){        Node currentNode=root;        int number=0;        for(int i=0;i<s.length();i++){            number=s.charAt(i)-'0';            if(currentNode.children[currentNode.children.length-1]!=null){                return false;            }            if(currentNode.children[number]==null){                currentNode.children[number]=new Node(number);            }            currentNode=currentNode.children[number];        }        if(currentNode.children[currentNode.children.length-1]==null){            currentNode.children[currentNode.children.length-1]=new Node(10);        }else{            return false;        }        return true;    }}public static void main(String[] args) {    Scanner input=new Scanner(System.in);    int number_of_test_cases=input.nextInt();    boolean istrue;    for(int i=0;i<number_of_test_cases;i++){        Trie tree=new Trie();        int length=input.nextInt();        String numbers[]=new String[length];        for(int j=0;j<numbers.length;j++){            numbers[j]=input.next();        }        Arrays.sort(numbers);        istrue=true;       for(int k=0;k<numbers.length;k++){        if(!tree.addChild(numbers[k])){            System.out.println(NO);            istrue=false;            break;        }        }        if(istrue){            System.out.println(YES);        }    }}}
Trie SPOJ Problem - PhoneList TLE
java;optimization;algorithm;strings;trie