You are viewing a single comment's thread. Return to all comments →
Try this. Simple and Straight. Passes all test cases. DO UPVOTE if you like the solution. Thank You.
public static String getSmallestAndLargest(String s, int k) { String smallest =s.substring(0,k); String largest = s.substring(0,k); int i=0; int j; while(i+k<=s.length()) { if(s.substring(i,i+k).compareTo(smallest) < 0 ) smallest = s.substring(i,i+k); else if(s.substring(i,i+k).compareTo(largest) > 0) largest = s.substring(i,i+k); i++; } return smallest + "\n" + largest; }
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 →
Try this. Simple and Straight. Passes all test cases. DO UPVOTE if you like the solution. Thank You.