Count the Good Pairs

Easy
array counting
Problem Description

Find the number of pairs (i,j) where nums[i] == nums[j] and i < j. Count all such valid pairs in the array.

Input Format
First line contains n (array size). Second line contains n integers separated by spaces.
Output Format
A single integer representing the number of good pairs.
Constraints
1 <= n <= 100
1 <= nums[i] <= 100
Sample Input/Output
Input:
4
1 2 3 1
Output:
1
Explanation

There is one good pair: (0,3) where nums[0] = nums[3] = 1 and 0 < 3.

Solution Hints
  • Read carefully: Understand input/output format and constraints
  • Start simple: Think of brute force solution first, then optimize
  • Edge cases: Consider empty inputs, single elements, max constraints
  • Data structures: Choose arrays, hash maps, sets based on problem needs
  • Time complexity: Ensure your solution fits within time limits
  • Test examples: Verify logic with provided sample inputs
75
Points
2000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback