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
- Split a given string into substrings of length K with equal sum of ASCII values
- Count of alphabets having ASCII value less than and greater than k
- Permutation of a string with maximum number of characters greater than its adjacent characters
- 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
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Program to find the XOR of ASCII values of characters in a string
- Count characters in a string whose ASCII values are prime
- Count pairs of characters in a string whose ASCII value difference is K
- Find the sum of the ascii values of characters which are present at prime positions
- Program to find the product of ASCII values of characters in a string
- Program to find the largest and smallest ASCII valued characters in a string
- Count number of substrings with numeric value greater than X
- Count substrings with same first and last characters
- Count of substrings whose Decimal equivalent is greater than or equal to K
- Queries for frequencies of characters in substrings
- Count of substrings formed using a given set of characters only
- Count of substrings having all distinct characters
- Recursive solution to count substrings with same first and last characters