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.
publicstaticStringgetSmallestAndLargest(Strings,intk){Stringsmallest="";Stringlargest="";// Complete the function// 'smallest' must be the lexicographically smallest substring of length 'k'// 'largest' must be the lexicographically largest substring of length 'k'intstart=0;smallest=s.substring(start,k);//give a starting point of the first 3 characterslargest=s.substring(start,k);while((start+k)<=s.length()){StringTemp=s.substring(start,start+k);smallest=(smallest.compareTo(Temp)>0)?Temp:smallest;largest=(largest.compareTo(Temp)<0)?Temp:largest;start++;}returnsmallest+"\n"+largest;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →