codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

ProblemsNumber of Good Pairs

Number of Good Pairs

Easy
HashingMath

Given an array of integers nums, return the number of good pairs.

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

 

Example 1:

Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5)

Example 2:

Input: nums = [1,1,1,1]
Output: 6

 

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Related Problems

View all
Two Sum
Easy•Hashing
Contains Duplicate
Easy•Hashing
Valid Anagram
Easy•Hashing
Group Anagrams
Medium•Hashing
Top K Frequent Elements
Medium•Hashing
Encode and Decode Strings
Medium•Hashing
Input:
nums = [1,2,3,1,1,3]