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 value for one query is different, unable to find the mistake in my formula
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intl=sc.nextInt();intq=sc.nextInt();sc.nextLine();Strings=sc.nextLine();//String[] var = s.split("");ArrayList<String>pal=newArrayList<String>();for(intk=0;k<s.length();k++){for(inti=k;i<s.length();i++){StringBuffersb=newStringBuffer();for(intj=k;j<=i;j++){sb.append(s.charAt(j));}Stringt1=sb.toString();Stringt2=sb.reverse().toString();//System.out.println(t1);if(t1.equals(t2)){pal.add(t1);}}}Collections.sort(pal);//System.out.println(pal);for(inti=0;i<q;i++){intr=sc.nextInt();inta=100001;doubleans=0;if(r>pal.size()||r<1){System.out.print("-1");continue;}Stringp=pal.get(r-1);intk=1;for(intj=0;j<p.length();j++){charc=p.charAt(j);//System.out.println(c);ans+=((int)(c)*(Math.pow(a,p.length()-j-1)));//%((Math.pow(10,9))+7);//System.out.println("");}ans=ans%((Math.pow(10,9))+7);System.out.println(ans);}/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Functional Palindromes
You are viewing a single comment's thread. Return to all comments →
the value for one query is different, unable to find the mistake in my formula