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) { Scanner scanner=new Scanner(System.in); String s=scanner.next(); int k=scanner.nextInt(); ArrayList<String> sub=new ArrayList<>(); for(int i=0;i<s.length();i++){ if(i < s.length()-(k-1)){ String subVals=s.substring(i,i+k); sub.add(subVals); } } Collections.sort(sub); String first=sub.get(0); String last=sub.get(sub.size()-1); System.out.print(first + "\n" + last); }
}
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 →
import java.io.; import java.util.;
public class Solution {
}