Given a string ‘str’, two integers ‘k’ and ‘p’. The task is to count all the sub-strings of ‘str’ having exactly ‘k’ characters that have ASCII value greater than ‘p’.
Input: str = “abcd”, k=2, p=98
Only the characters ‘c’ and ‘d’ have ASCII values greater than 98,
And, the sub-strings containing them are “abcd”, “bcd” and “cd”.
Input: str = “sabrcd”, k=5, p=80
Approach: We just need to iterate over all indices and take all possible length sub-strings and then just check whether the sub-string has exactly ‘k’ characters that have ASCII value greater than ‘p’.
Typecasting a character to int will give us it’s ASCII value i.e.
int ascii = (int) char.
Below is the implementation of the above approach:
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Count of alphabets having ASCII value less than and greater than k
- Count the number of words having sum of ASCII values less than and greater than k
- Average of ASCII values of characters of a given string
- Count number of substrings with numeric value greater than X
- Count characters in a string whose ASCII values are prime
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Count pairs of characters in a string whose ASCII value difference is K
- Count substrings with same first and last characters
- 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
- Queries for frequencies of characters in substrings
- Program to find the largest and smallest ASCII valued characters in a string
- Count distinct substrings that contain some characters at most 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.