03. Number of Good Pairs
The problem can be found at the following link: Question Link
My Approach
Initialize an unordered map of
int
.Iterate through the given values in the array. For each piece in the iteration:
Check if the current value is present in the map or not If yes, increment
count
as it is a valid pair.If it is not present in the map then insert the value in the map
Return
count
which stores the count of all valid pairs .
Time and Auxiliary Space Complexity
Time Complexity:
O(n)
Auxiliary Space Complexity:
O(n)
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 rishabhv12/Daily-Leetcode-Solution repository.
Last updated