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.
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- K-th lexicographically smallest unique substring of a given string
- 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 rotated sequence | Set 2
- Construct lexicographically smallest palindrome
- Lexicographically smallest string of length N and sum K
- Lexicographically largest sub-sequence of the given string
- Make a lexicographically smallest palindrome with minimal changes
- Lexicographically smallest permutation of a string with given subsequences
- Queries to answer the X-th smallest sub-string lexicographically
- Swap all occurrences of two characters to get lexicographically smallest string
- Lexicographically smallest permutation with no digits at Original Index
- Lexicographically smallest string formed by removing at most one character
- Find the lexicographically smallest string which satisfies the given condition
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.