Count Pairs Divisible by K

You are given an array ARR and a positive integer K. Your task is to count the total number of pairs within the array whose sum is divisible by K.

Example:

Input:
ARR = [4, 3, 5, 1, 4, 5], K = 5
Output:
3
Explanation:

The pairs whose sums are divisible by 5 are [4, 1], [5, 5], and [4, 1]. Thus, there are 3 pairs.

Constraints:

  • 1 <= T <= 10
  • 2 <= N < 10^6
  • 1 <= K <= 10^9
  • 0 <= arr[i] <= 10^9
  • Time Limit: 1 sec
Note:
You do not need to print anything. It has already been taken care of. Just implement the function.
Be the first one to answer
Add answer anonymously...
MathWorks Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter