Ninja And Divisible Array Problem Statement

Ninja is tasked with dividing an array ARR of even size N and an integer K into N/2 pairs such that the sum of each pair is divisible by K.

Your goal is to determine if this task can be accomplished.

Input:

The first line contains an integer T representing the number of test cases. 
For each test case, the first line contains two space-separated integers N and K, denoting the size of the array and the divisor value. The following line contains N space-separated integers representing the elements of ARR.

Output:

For each test case, output "true" if it is possible to pair the array elements such that the sum of each pair is divisible by K, otherwise output "false". Each result should be on a separate line.

Example:

Input:
ARR = [4, 5, 6, 5, 7, 3], K = 5
Output:
true
Explanation:

Pairs such as (4, 6), (5, 5), and (7, 3) have sums 10, 10, and 10 respectively, which are all divisible by 5.

Constraints:

  • 1 ≤ T ≤ 50
  • 2 ≤ N ≤ 10000
  • 1 ≤ K ≤ 100000
  • -100000 ≤ ARR[i] ≤ 100000

Where ARR[i] represents the value of the array.

Time limit: 1 sec

Note:

You don’t need to print anything; It has already been taken care of. Just implement the given function.

Be the first one to answer
Add answer anonymously...
Infosys System Engineer 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