02. First element to occur k times
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
We use an unordered map to store the frequency of each element while iterating through the array.
At each step, we check if the frequency of the current element equals k. If it does, we return that element.
If no such element is found, we return -1.
Time Complexity: O(n) - We iterate through the array once.
Auxiliary Space Complexity: O(n) - We use an unordered map to store the frequency of elements.
For discussions, questions, or doubts related to this solution, please visit our . 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 repository.