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=s.substring(0,k);Stringlargest=s.substring(0,k);// Complete the function// 'smallest' must be the lexicographically smallest substring of length 'k'// 'largest' must be the lexicographically largest substring of length 'k'for(inti=0;i<=s.length()-k;i++){if(s.substring(i,i+k).compareTo(smallest)<=0){smallest=s.substring(i,i+k);}if(s.substring(i,i+k).compareTo(largest)>=0){largest=s.substring(i,i+k);}}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 →