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.
// Complete the twoCharaters function below.staticinttwoCharaters(Strings){for(inti=1;i<s.length();i++){if(s.charAt(i-1)==s.charAt(i)){s=s.replace(s.charAt(i)+"","");i=0;}}String[][]map=newString[26][26];intr=0;for(inti=0;i<s.length();i++){r=((int)s.charAt(i))-97;for(intj=0;j<26;j++){//System.out.println("[j][r] "+j+","+r);if(map[j][r]==null)map[j][r]=s.charAt(i)+"";elseif(map[j][r].equals("N")){}elseif(map[j][r].charAt(map[j][r].length()-1)!=s.charAt(i))map[j][r]+=s.charAt(i);elsemap[j][r]="N";if(map[r][j]==null)map[r][j]=s.charAt(i)+"";elseif(map[r][j].equals("N")){}elseif(map[r][j].charAt(map[r][j].length()-1)!=s.charAt(i))map[r][j]+=s.charAt(i);elsemap[r][j]="N";}}r=0;for(inti=0;i<26;i++){for(intj=0;j<26;j++){if(map[i][j]!=null&&map[i][j].length()>1&&r<map[i][j].length())r=map[i][j].length();}}returnr;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
wrote a clumsy one.