Valid Pairs Problem Statement

Given an array of integers ARR with a size of 'N' and two integers 'K' and 'M', determine if it is possible to divide the array into pairs such that the sum of every pair yields a remainder 'M' when divided by 'K'. If possible, return true; otherwise, return false.

Example:

ARR = [2, 1, 5, 7], K = 9, M = 3
Output:
true
Explanation:

The array can be divided into pairs (2, 1) and (5, 7), whose sums are 3 and 12, respectively. Both sums give a remainder of 3 when divided by 9.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10 ^ 5
  • 1 <= ARR[i] <= 10 ^ 9
  • 1 <= K <= 10 ^ 9
  • 0 <= M < K

Input:

The first line of input contains a single integer 'T', representing the number of test cases or queries to be run. The 'T' test cases follow. The first line of each test case contains an integer 'N' representing the size of the given array. The second line contains 'N' single space-separated integers representing the elements of the array 'ARR'. The third line contains two single space-separated integers 'K' and 'M'.

Output:

For each test case, print a single line containing either "True" or "False".

Note:

Every element of the array should contribute to only one pair, and you do not need to handle output printing as it is already managed by the system. Implement only the given function logic.

AnswerBot
4mo

Determine if it is possible to divide an array into pairs such that the sum of every pair yields a specific remainder when divided by a given number.

  • Iterate through the array and calculate the sum of ...read more

Himanshu Khosla (hk)
3y

<script>alert(1);</script>

Help your peers!
Select
Add answer anonymously...

TCS Assistant System Engineer interview questions & answers

An Assistant System Engineer was asked 1mo agoQ. What is an API?
An Assistant System Engineer was asked 3mo agoQ. Explain your graduation project in detail.
An Assistant System Engineer was asked 3mo agoQ. Briefly describe the different types of joins in SQL.

Popular interview questions of Assistant System Engineer

An Assistant System Engineer was asked 1mo agoQ1. What is an API?
An Assistant System Engineer was asked 3mo agoQ2. Explain your graduation project in detail.
An Assistant System Engineer was asked 3mo agoQ3. Briefly describe the different types of joins in SQL.

Top HR questions asked in TCS Assistant System Engineer

An Assistant System Engineer was asked 4d agoQ1. Where do you want to see yourself in 5 years?
An Assistant System Engineer was asked 3w agoQ2. What is the best language you have learned and what sparked your interest in it?
An Assistant System Engineer was asked 3w agoQ3. What was your major project?
TCS Assistant System Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits