Given q explanation and soln in cpp

given an array of integer and numbers k and m, write a function that return true if given array can divide into pairs such that the sum of every pairs gives remainder m when divided by .

input 4

2

1 5 7

9

3

output true

hello @Kash-Moulik-3715574511847721 do you want code for this question ?

explanation and code both

@Kash-Moulik-3715574511847721 okay wait .

hey @Kash-Moulik-3715574511847721 let us take the simple example when m is 0 .
so that it should not complicate you in understanding at very first .
first of all for handing test cases if the lenght of the array is odd then we cannot make its pair so return false if it is the case.
then we come to the process when we will find the remainders of all the array elements .
there can be array numbers negative as well and it can give negative result as well .
so for that you can find remainder like
((arr[i]%k)+k)%k
and you should maintain one freq count as well of the remainders .

then finally come the major task when you have to do the check.
you will run the loop for n times i.e the size of the array .
find the remainder of that particular arrray element and check with the help of the freq of the remainder
if the remainder *2 isequal to k then there is pair
if this is not then there put another else if condition that If remainder is 0, then there must be two elements with 0 remainder.
Else number of occurrences of remaindermust be equal to number of occurrences of k - remainder.
if you dont understan anything you can ask here .
Happy Learning !!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.