
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.

AnswerBot
6d

The task is to determine if an array can be divided into pairs such that the sum of each pair is divisible by a given integer.
Iterate through the array and calculate the remainder of each element when...read more

Help your peers!
Add answer anonymously...
Top Infosys System Engineer interview questions & answers
Popular interview questions of System Engineer
Top HR questions asked in Infosys System Engineer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app