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
- Queries to find the count of vowels in the substrings of the given string
- Count of distinct substrings of a string using Suffix Trie
- Count number of substrings of a string consisting of same characters
- 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 subsequence of length three in a given string
- Count maximum-length palindromes in a String
- Contiguous unique substrings with the given length L
- 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 with same first and last characters
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.