You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { var entry = new Scanner(System.in); String s = entry.next(); int k = entry.nextInt(); System.out.println(getSmallestAndLargest(s, k)); } private static String getSmallestAndLargest(String s, int k){ var lista = new ArrayList<String>(); for (int i = 0; i <= s.length()-k; i++){ String subS = s.substring(i, i+k); lista.add(subS); } Collections.sort(lista); return lista.get(0) + "\n" + lista.get(lista.size()-1); } }
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 →