Given a string and a number k, the task is to find the number of substrings of length k whose sum of ASCII value of characters is divisible by k.
Input : str = “bcgabc”, k = 3
Output : 2
Substring “bcg” has sum of ASCII values 300 and “abc” has sum of ASCII values 294 which are divisible by 3.
Input : str = “adkf”, k = 3
Output : 1
Approach: First, we find the sum of ASCII value of characters of first substring of length k, then using sliding window technique subtract ASCII value of first character of the previous substring and add ASCII value of the current character. We will increase the counter at each step if sum is divisible by k.
Below is the implementation of above approach:
- Program to find the product of ASCII values of characters in a string
- Find the sum of the ascii values of characters which are present at prime positions
- Number of substrings divisible by 8 but not by 3
- Program to find the largest and smallest ASCII valued characters in a string
- Number of substrings divisible by 6 in a string of integers
- Count number of substrings with exactly k distinct characters
- Count number of substrings of a string consisting of same characters
- Count number of distinct substrings of a given length
- Find distinct characters in distinct substrings of a string
- Sub-strings having exactly k characters that have ASCII value greater than p
- Average of ASCII values of characters of a given string
- Count characters in a string whose ASCII values are prime
- Count pairs of characters in a string whose ASCII value difference is K
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with 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.