forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
31 lines (24 loc) · 780 Bytes
/
Solution.java
File metadata and controls
31 lines (24 loc) · 780 Bytes
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static String getSmallestAndLargest(String s, int k) {
ArrayList<String> cache = new ArrayList<>();
for (int i = 0; i <= s.length() - k; i++) {
cache.add(s.substring(i, i + k));
}
Collections.sort(cache);
String smallest = cache.get(0);
String largest = cache.get(cache.size() - 1);
return smallest + "\n" + largest;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
int k = scan.nextInt();
scan.close();
System.out.println(getSmallestAndLargest(s, k));
}
}