Skip to main content
Back to problems
Leetcode
Easy
Arrays
Hash Maps
Find The Number Of Good Pairs I

Count the number of index pairs whose values satisfy a simple equality condition.

Acceptance 0%
Problem Statement

Problem

Given an integer array nums and an integer k, count the number of good pairs (i, j) such that:

  • i < j
  • nums[i] == nums[j]
  • i * j is divisible by k

Return the total number of good pairs.

This is a counting problem where each pair of equal values may or may not qualify based on the index-product divisibility condition.

Input Format

  • nums: an integer array
  • k: a positive integer

Output Format

  • Return an integer representing the number of good pairs.

Constraints

  • 1 <= nums.length (exact limits unknown from the provided context)
  • k > 0
  • Indices are 0-based
  • Count each valid pair once
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,3,1,1,3], k = 1

Output

4

Explanation

All equal-value pairs are valid because every product is divisible by 1. The good pairs are (0,3), (0,4), (3,4), and (2,5).

Example 2

Input

nums = [1,2,1,2,1], k = 2

Output

1

Explanation

Equal-value pairs are (0,2), (0,4), and (2,4) for value 1, plus (1,3) for value 2. Only (1,3) has index product 3 divisible by 2? No, so none of these qualify except any pair whose product is divisible by 2. Here only (0,2) and (0,4) qualify because 0 multiplied by anything is divisible by 2. Total = 2.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.