You are on page 1of 2

Problems Courses Get Hired Contests POTD  

 Problem  Editorial  Submissions  Comments

Editorial 

Expected Approach
Intuition
The idea is to collect those elements which have the same remainder when

divided by K.

Implementation
Step 1: We first replace the array elements with the remainder divided by

K.

Step 2: Let's say there are x array elements with remainder m, then the

total pairs will be: (x*(x-1))/2.

Step 3: Now we add all the pairs of all the remainders, to the sum and

return the sum.

Complexity
Time Complexity: The time complexity will be O(n).

Space Complexity: A s we are storing the remainders, the space

complexity will be O(K).

View Author's Solution

Useful links to help you understand the concepts of this problem:

https://www.geeksforgeeks.org/count-pairs-in-an-array-whose-absolute-diff

erence-is-divisible-by-k/

Menu 
Menu 

You might also like