Can anyone tell me how to solve these two problems?
I saw the solutions of others but am unable to understand the approach.
Can anyone tell me how to solve these two problems?
I saw the solutions of others but am unable to understand the approach.
Query on tree uses HLD of trees.
Avani and magic requires you to use Tries.
If you want author’s solutions for the problems, you can request below in the comments.
thank you. Please provide the solution. That would help a lot.
import java.io.;
import java.util.ArrayList;
/
'); len= m.length(); pointer=0; tem=vertex.get(0); while(len>0){ ch=m.charAt(pointer)-96; pointer++; if(tem[ch]==0){ arr=new int[7]; arr[5]=Integer.MAX_VALUE; vertex.add(arr); size++; tem[ch]=size-1; if(ch<tem[5]){ tem[5]=ch; } if(tem[6]<ch){ tem[6]=ch; } } tem=vertex.get(tem[ch]); len--; } } q=Integer.parseInt(br.readLine()); for (int i = 0; i < q; i++) { tem=vertex.get(0); ans=new StringBuilder(); pre=0; m=new StringBuilder(br.readLine()); m=m.append('
’);Thanks alot
For Query on tree, you can refer to anybody’s solution. They are almost same.