-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Solution.java
31 lines (26 loc) · 875 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
int k = scan.nextInt();
scan.close();
/* Create smallest and largest strings and initialize them */
String smallest = s.substring(0, k);
String largest = s.substring(0, k);
for (int i = 0; i <= s.length() - k; i++) {
String curr = s.substring(i, i + k);
if (smallest.compareTo(curr) > 0){
smallest = curr;
}
if (largest.compareTo(curr) < 0) {
largest = curr;
}
}
/* Print results */
System.out.println(smallest);
System.out.println(largest);
}
}