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.
Java - hahahaha I did a bubble sort thinking I actually needed every substring in order...oh well, I needed the practice anyway lol
publicstaticStringgetSmallestAndLargest(Strings,intk){Stringsmallest="";Stringlargest="";intnumSubs=s.length()-k+1;String[]subs=newString[numSubs];for(inti=0;i<numSubs;i++){subs[i]=s.substring(i,i+k);}Stringtemp="";//BUBBLE SORT TIME YAYYYYYYYYfor(inti=0;i<numSubs-1;i++){for(intj=0;j<numSubs-i-1;j++){if(subs[j].compareTo(subs[j+1])>0){temp=subs[j];subs[j]=subs[j+1];subs[j+1]=temp;}}}smallest=subs[0];largest=subs[numSubs-1];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 →
Java - hahahaha I did a bubble sort thinking I actually needed every substring in order...oh well, I needed the practice anyway lol