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
12h

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)
2y

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

Help your peers!
Add answer anonymously...
TCS Assistant 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