Given a string str and an integer N, the task is to find the number of possible sub-strings of length N.
Input: str = “geeksforgeeks”, n = 5
All possible sub-strings of length 5 are “geeks”, “eeksf”, “eksfo”,
“ksfor”, “sforg”, “forge”, “orgee”, “rgeek” and “geeks”.
Input: str = “jgec”, N = 2
Approach: The count of sub-strings of length n will always be len – n + 1 where len is the length of the given string. For example, if str = “geeksforgeeks” and n = 5 then the count of sub-strings having length 5 will be “geeks”, “eeksf”, “eksfo”, “ksfor”, “sforg”, “forge”, “orgee”, “rgeek” and “geeks” which is len – n + 1 = 13 – 5 + 1 = 9.
Below is the implementation of the above approach:
- Count all Prime Length Palindromic Substrings
- Count number of distinct substrings of a given length
- Count of substrings of a binary string containing K ones
- Count the number of vowels occurring in all the substrings of given string
- Count of distinct substrings of a string using Suffix Array
- Given a binary string, count number of substrings that start and end with 1.
- Count of distinct substrings of a string using Suffix Trie
- Count subsequence of length three in a given string
- Count maximum-length palindromes in a String
- Convert all substrings of length 'k' from base 'b' to decimal
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Count substrings that contain all vowels | SET 2
- Count substrings with same first and last characters
- Number of substrings with count of each character as k
- Count of substrings which contains a given character K times
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.