Pairs which are Divisible by 4
Easy Accuracy: 56.99% Submissions: 1512 Points: 2

Given an array, if ‘n’ positive integers, count the number of pairs of integers in the array that have the sum divisible by 4.

Example 1:

Input : Arr[] = {2, 2, 1, 7, 5}
Output : 3
(2,2), (1,7) and(7,5) are the 3 pairs.

Example 2:

Input : Arr[] = {2, 2, 3, 5, 6}
Output : 4


Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function count4Divisibiles() that takes an array (arr), sizeOfArray (n), and return the number of pairs. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).


1 ≤ N ≤ 105

1 ≤ arr[] ≤ 105

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Pairs which are Divisible by 4

Output Window