Given a string, find count of number of larger alphabets for every character of the string.
Input : str = "abcd" Output : 3 2 1 0 There are 3 greater characters on right of 'a', 2 greater characters on right of 'b', 1 greater character on right of 'c' and 0 greater characters on right of 'd'. Input : geeks Output : 2 2 2 1 0
A naive approach is to use two for loops. First will keep track of each alphabet in string and second loop will be used to find no of larger alphabet according to ASCII values.
3 2 1 0
Time Complexity : O(N * N)
An efficient approach is to traverse the string from right and keep track of counts of characters from right side. For every character that we traverse from right, we increment its count in count array and add counts of all greater characters to answer for this character.
3 2 1 0
Time Complexity : O(N)
- Number of elements that can be seen from right side
- Maximum difference between two elements such that larger element appears after the smaller number
- Find elements larger than half of the elements in an array
- Minimizing array sum by subtracting larger elements from smaller ones
- Remove minimum elements from either side such that 2*min becomes more than max
- Count smaller elements on right side using Set in C++ STL
- Count smaller elements on right side
- Check if a larger number divisible by 36
- Smallest triangular number larger than p
- Server side and Client side Programming
- Number of squares of side length required to cover an N*M rectangle
- Minimum number of points to be removed to get remaining points on one side of axis
- Find larger of x^y and y^x
- Next Larger element in n-ary tree
- Count number of elements between two given elements in array
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.