Array Pair Sum Divisibility Problem
In this class, We discuss Array Pair Sum Divisibility Problem.
Readers can prepare an entire competitive coding course to crack product development companies. Click Here.
The reader should have basic coding skills to work with competitive coding. Click here.
Question:
Given an array of integers.
Our task is to find the given array that can be divided to pair of elements, such that the sum of elements of each pair is divisible by K.
Example:
Input: A = [9, 5, 7, 3]
K = 6
Output = 1
We can divide the elements into pairs (9,3) and (5, 7).
Both the pairs elements sum is divisible by 6.
The output is one because there is a possibility to divide into pairs.
If the division is not possible, then return -1.
Time Complexity: O(N)
Space Complexity: O(N)
Logic:
We can do the program in the given time using a hash table.
The step-by-step explanation is provided in the video.
Code: