15. Count the elements
The problem can be found at the following link: Question Link
My Approach
To count the elements in vector a
based on the occurrences in vector b
, I follow these steps:
Create a frequency array
mp
to count the occurrences of elements in vectorb
.Traverse through vector
a
and count the number of elements less than or equal to the current element.Store the counts in the output vector for corresponding queries.
Time and Auxiliary Space Complexity
Time Complexity: O(N + Q), where N is the size of vector
a
and Q is the number of queries.Auxiliary Space Complexity: O(nax), where nax is the maximum element present in vector
a
.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated