I solve https://www.codeeval.com/open_challenges/83/ my code:

static void fb(String line){ String s =line.toLowerCase(); char[] Myarr=s.toCharArray(); Arrays.sort(Myarr); //System.out.println(Arrays.binarySearch(Myarr,'a')); int r=26; int ret=0; int k=0; boolean fl=false; int[] arrK=new int[Myarr.length]; k=arrK.length; char ch='z'+1; for (int i=k-1;i>=0;i--){ if (Myarr[i]==ch){ arrK[k]++; } else { k--; ch=Myarr[i]; arrK[k]++; } if (ch<'a') break; } k=arrK.length-1; for (int ii=k;ii>=0;ii--) { if (arrK[ii]==0) break; //System.out.print(ii); ret = ret + (r*arrK[ii]); r--; } /* for (char i='z';i>='a';i--){ fl=false; while (true){ k=Arrays.binarySearch(Myarr,i); if (k>=0){ //System.out.print(i+":"+Arrays.binarySearch(Myarr,i)+" "); ret=r+ret; //System.out.print(ret+" "); fl=true; Myarr[k]=' '; Arrays.sort(Myarr); for (int jj=0;jj<Myarr.length;jj++){System.out.print(Myarr[jj]);} System.out.println("----"+r+" : "+ret); //System.out.print(i+":"+Arrays.binarySearch(Myarr,i)+" "); } else { if (fl){ r--; } break; } } } */ System.out.println(line+":"+ret);/* for (int k=0;k<Myarr.length;k++){ System.out.print(Myarr[k]+"|"); } System.out.println("");*/ } 

For the first test line, the result is beating, for the others there is none. Help!!! :)

    1 answer 1

    You were caught on the condition that you have the wrong algorithm. Nobody said that beauty 'a' is less than beauty 'b'. The most beautiful letter is the one with the most in the phrase. Only then the beauty of the phrase will be maximized. For example, in the second phrase the most beautiful 'c', 'e' and 'o', they occur 4 times. And the beauty of each of them, respectively, 26, 25 and 24.

    Threat code put in order ...