Write a Java Program to find Lexicographically smallest and largest substring of length k. This problem is derived from the String section of Hackerrank in java. I like this problem, so i decided to put my solution on my site.Below is the question and solution of the problem.
Java String Compare
Given a string, find out the lexicographically smallest and largest substring of length k.
Input Format
First line will consist a string containing english alphabets which has at most characters. 2nd line will consist an integer .
Output Format
In the first line print the lexicographically minimum substring. In the second line print the lexicographically maximum substring.
Sample Input
Sample Output
Explanation
Here is the list of all substrings of length :
Among them ava is the smallest and wel is the largest.
Here below is the source code of the above problem which is successfully compiled and run on Hackerrank code editor as well as on Windows System to produce desired result.Let’s check out the program below :
SOURCE CODE :
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer