Skip to content

Practice Count Equal and Divisible Pairs in an Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2176
LeetCode Problem

Count Equal and Divisible Pairs in an Array

Problem Statement

Count index pairs (i, j) with i < j for which nums[i] equals nums[j] and the index product i * j is divisible by k. Indices are zero-based. Repeated values at different indices form different candidate pairs. Practice approach: Enumerate each pair once using an outer index and a later inner index, then test both conditions. The array has at most 100 entries, so O(n^2) time is sufficient with O(1) extra space. Remember that index zero makes the product zero, which is divisible by every allowed k.

Source: Count Equal and Divisible Pairs in an Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,1,2,2,2,1,3], k = 2
Output
4

# Example 2

Input
nums = [1,2,3,4], k = 1
Output
0

Constraints

1 <= nums.length <= 100
1 <= nums[i], k <= 100

Related LeetCode Problems

Practice more problems similar to Count Equal and Divisible Pairs in an Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.