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
4mo
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...
Infosys System Engineer interview questions & answers
A System Engineer was asked 2w agoQ. What is method overriding?
A System Engineer was asked 2w agoQ. What is the process for reversing a number?
A System Engineer was asked 2w agoQ. What are the details of Object-Oriented Programming (OOP) concepts?
Popular interview questions of System Engineer
A System Engineer was asked 2w agoQ1. What is the process for reversing a number?
A System Engineer was asked 2w agoQ2. What is method overriding?
A System Engineer was asked 2w agoQ3. What are the details of Object-Oriented Programming (OOP) concepts?
Top HR questions asked in Infosys System Engineer
A System Engineer was asked 2mo agoQ1. Explain your project.
A System Engineer was asked 3mo agoQ2. Explain your final semester project.
A System Engineer was asked 3mo agoQ3. What was your involvement in your college project?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

