Given a string, the task is to count the number of words whose sum of Ascii values is less than and greater than or equal to given k.
Input: str = "Learn how to code", k = 400 Output: Number of words having sum of ascii less than k = 2 Number of words having sum of ascii greater than or equal to k = 2 Input: str = "Geeks for Geeks", k = 400 Output: Number of words having sum of ascii less than k = 1 Number of words having sum of ascii greater than or equal to k = 2
Approach: Count the number of words having the sum of ASCII values less than k and subtract it from the total number of words to get the number of words having ASCII values to the sum greater than or equal to k. Start traversing the string letter by letter and add the ASCII value to sum. If there is a space then increment the count if the sum is less than k and will also set the sum to 0.
Below is the implementation of the above approach:
Number of words having sum of ASCII values less than k = 2 Number of words having sum of ASCII values greater than or equal to k = 2
Time Complexity: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of alphabets having ASCII value less than and greater than k
- Count characters in a string whose ASCII values are prime
- Sub-strings having exactly k characters that have ASCII value greater than p
- Count the number of words with given prefix using Trie
- Map function and Dictionary in Python to sum ASCII values
- Average of ASCII values of characters of a given string
- Convert a string to hexadecimal ASCII values
- Sums of ASCII values of each word in a sentence
- Minimize ASCII values sum after removing all occurrences of one character
- Print each word in a sentence with their corresponding average of ASCII values
- Check if a string contains only alphabets in Java using ASCII values
- Program to find the XOR of ASCII values of characters in a string
- Find the sum of the ascii values of characters which are present at prime positions
- Split a given string into substrings of length K with equal sum of ASCII values
- Program to find the product of ASCII values of characters in a string
- Count words that appear exactly two times in an array of words
- Count number of substrings with numeric value greater than X
- Find words which are greater than given length k
- Find words which are greater than given length k using stringstream
- Count number of binary strings such that there is no substring of length greater than or equal to 3 with all 1's
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.