Given String str and an integer k, find the lexicographically smallest and largest substring of length k
Lexicography order, also called as alphabetical order or dictionary order,
A < B <... < Y < Z < a < b <.. < y < z
Input : String: hello Size: 2 Distinct Substring: [el, he, ll, lo] Output : Smallest Substring: el Largest Substring: lo Input : String: geeksforgeeks Size: 3 Distinct Substring: [eek, eks, for, gee, ksf, org, rge, sfo] Output : Smallest Substring: eek Largest Substring: sfo
We initialize max and min as first substring of size k. We traverse remaining substrings, by removing first character of previous substring and adding last character of new string. We keep track of the lexicographically largest and smallest.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Lexicographically smallest and largest anagrams of a string containing another string as its substring
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- K-th lexicographically smallest unique substring of a given string
- Lexicographically smallest K-length substring containing maximum number of vowels
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Generate a string of size N whose each substring of size M has exactly K distinct characters
- Check if string can be made lexicographically smaller by reversing any substring
- Lexicographically largest string formed from the characters in range L and R
- Generate lexicographically smallest string of 0, 1 and 2 with adjacent swaps allowed
- Form lexicographically smallest string with minimum replacements having equal number of 0s, 1s and 2s
- Lexicographically smallest string of length N and sum K
- Make the string lexicographically smallest and non palindromic by replacing exactly one character
- Make the string lexicographically smallest and non palindromic by swapping of adjacent pair of characters
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Lexicographically largest subsequence such that every character occurs at least k times
- Find the lexicographically largest palindromic Subsequence of a String
- Lexicographically largest sub-sequence of the given string
- Lexicographically largest possible String after removal of K characters
- Lexicographically largest string for given dictionary order
- Lexicographically largest string possible in one swap
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.