Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Java Strings English

This document discusses finding the lexicographically smallest and largest substrings of length k from a given string. It provides an example input of the string "welcometojava" and substring length k of 3. The output provides the smallest substring "ava" and largest substring "wel" from all possible substrings of length 3 in the given string.

Uploaded by

Watan Sahu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Java Strings English

This document discusses finding the lexicographically smallest and largest substrings of length k from a given string. It provides an example input of the string "welcometojava" and substring length k of 3. The output provides the smallest substring "ava" and largest substring "wel" from all possible substrings of length 3 in the given string.

Uploaded by

Watan Sahu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Java

strings
Problem Statement
Today we will learn about java strings. Your task is simple, given a string, find out the lexicographically
smallest and largest substring of length k.
[Note: Lexicographic order is also known as alphabetic order dictionary order. So "ball" is smaller than "cat",
"dog" is smaller than "dorm". Capital letter always comes before smaller letter, so "Happy" is smaller than
"happy" and "Zoo" is smaller than "ball".]
Input Format
First line will consist a string containing english alphabets which has at most 1000 characters. 2nd line will
consist an integer k.
Output Format
In the first line print the lexicographically minimum substring. In the second line print the lexicographically
maximum substring.
Sample Input
welcometojava
3

Sample Output
ava
wel

Explanation
Here is the list of all substrings of length 3:
wel
elc
lco
com
ome
met
eto
toj
oja
jav
ava

Among them ava is the smallest and wel is the largest.

You might also like