You are viewing a single comment's thread. Return to all comments →
public static String getSmallestAndLargest(String s, int k) {
String smallest = s.substring(0, k); String largest = smallest; for (int x=1; x<=s.length()-k; x++) { String tempSub = s.substring(x, x+k); smallest = (tempSub.compareTo(smallest)<0) ? tempSub : smallest; largest = (tempSub.compareTo(largest)>0) ? tempSub : largest; } return smallest + "\n" + largest; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →
public static String getSmallestAndLargest(String s, int k) {