We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscan=newScanner(System.in);Strings;s=scan.nextLine();intk=scan.nextInt();Stringsmall=s.substring(0,k);Stringlarge=s.substring(0,k);for(inti=1;i<=s.length()-k;i++){Stringsub=s.substring(i,i+k);if(sub.compareTo(small)<0){small=sub;}if(sub.compareTo(large)>0){large=sub;}}System.out.println(small+"\n"+large);scan.close();}}
Cookie support is required to access HackerRank
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 →