You are viewing a single comment's thread. Return to all comments →
My solution:
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); int k = sc.nextInt(); String smallest = ""; String largest = ""; sc.close(); ArrayList<String> arrayList = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { if ((i + k) <= s.length()) { arrayList.add(s.substring(i, i + k)); } } smallest = Collections.min(arrayList); largest = Collections.max(arrayList); System.out.println(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 →
My solution: