We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
the below code passes just 2 test cases. Can someone point me in the right direction?
staticclassTN{TNarr[]=newTN[26];booleanisEnd=false;}staticTNtn=newTN();staticintfun(TNt,intan){if(t.isEnd)an++;for(inti=0;i<26;i++){if(t.arr[i]!=null){returnfun(t.arr[i],an);}}returnan;}/* * Complete the contacts function below. */staticint[]contacts(String[][]queries){/* * Write your code here. */List<Integer>list=newArrayList<>();for(intit=0;it<queries.length;it++){Stringf=queries[it][0];Strings=queries[it][1];System.out.println(s);if(f.equals("add")){TNt=tn;for(inti=0;i<s.length();i++){if(t.arr[s.charAt(i)-'a']!=null){t=t.arr[s.charAt(i)-'a'];}else{t.arr[s.charAt(i)-'a']=newTN();t=t.arr[s.charAt(i)-'a'];}if(i==s.length()-1){t.isEnd=true;}}}else{TNt=tn;for(inti=0;i<s.length();i++){if(t.arr[s.charAt(i)-'a']!=null){t=t.arr[s.charAt(i)-'a'];}else{list.add(0);continue;}if(i==s.length()-1){list.add(fun(t,0));}}}}intnn=list.size();intar[]=newint[nn];for(inti=0;i<nn;i++){ar[i]=list.get(i);}returnar;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Contacts
You are viewing a single comment's thread. Return to all comments →
the below code passes just 2 test cases. Can someone point me in the right direction?