# 03. Number of Good Pairs

The problem can be found at the following link: [Question Link](https://leetcode.com/problems/number-of-good-pairs/description/)

## My Approach

1. Initialize an unordered map of `int`.
2. 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
3. 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++)

```cpp

class Solution {
public:
    int numIdenticalPairs(vector<int>& a) {
        int i,count=0;

        unordered_map<int,int>map;

        for(i=0;i<a.size();i++){
            if(map.find(a[i])!=map.end())
            count +=map[a[i]];
                
            map[a[i]]++;
        }
        return count;
    }
};

```

## Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our [discussion section](https://leetcode.com/discuss/general-discussion). 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](https://github.com/rishabhv12/Daily-Leetcode-Solution) repository.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://code-render.gitbook.io/leetcode-editorials/10-october/03-number-of-good-pairs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
