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.
- K-th lexicographically smallest unique substring of a given string
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Check if string can be made lexicographically smaller by reversing any substring
- Lexicographically smallest string of length N and sum K
- Lexicographically smallest rotated sequence | Set 2
- Construct lexicographically smallest palindrome
- Lexicographically largest sub-sequence of the given string
- Make a lexicographically smallest palindrome with minimal changes
- Queries to answer the X-th smallest sub-string lexicographically
- Lexicographically smallest permutation of a string with given subsequences
- Lexicographically smallest string formed by removing at most one character
- Lexicographically smallest string obtained after concatenating array
- Find the lexicographically smallest string which satisfies the given condition
- Lexicographically smallest permutation with no digits at Original Index
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.