`{"id":"7c7ddf01-9499-4961-9819-1c444c037a5c","name":"Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K","description":"1. You are given an array(arr) of integers and a number K.\r\n2. You have to find if the given array can be divided into pairs such that the sum of every pair is divisible by k.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nA number K","outputFormat":"true or false.","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^4\r\n1 &lt;= K &lt;= 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvoid solution(vector<int> &arr, int k){\n\t// write your code here\n}\nint main() {\n\tint n = 0;\n\tcin >> n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tcin >> arr[i];\n\t}\n\tint k = 0;\n\tcin >> k;\n\tsolution(arr, k);\n\treturn 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static void solution(int[] arr, int k){\r\n\t\t//write your code here\r\n\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tint k = scn.nextInt();\r\n\t\tsolution(arr,k);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n9 7 5 3\r\n6","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/BvKv-118twg?end=42","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"7abe74c6-9ce8-4346-a730-360b52b932f6","name":"Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K","slug":"check-if-an-array-can-be-divided-into-pairs-whose-sum-is-divisible-by-k","type":1}],"next":{"id":"ea99999a-e1df-442a-8817-ae454c329d35","name":"Check if an Array can be Divided into Pairs whose Sum is Divisible by K MCQ","type":0,"slug":"check-if-an-array-can-be-divided-into-pairs-whose-sum-is-divisible-by-k-mcq"},"prev":{"id":"75948f9a-ccd6-48e0-8c3f-7845d46040cc","name":"Find Itinerary From Tickets","type":3,"slug":"find-itinerary-from-tickets"}}}`

# Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K

1. You are given an array(arr) of integers and a number K. 2. You have to find if the given array can be divided into pairs such that the sum of every pair is divisible by k.

`{"id":"7c7ddf01-9499-4961-9819-1c444c037a5c","name":"Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K","description":"1. You are given an array(arr) of integers and a number K.\r\n2. You have to find if the given array can be divided into pairs such that the sum of every pair is divisible by k.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nA number K","outputFormat":"true or false.","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^4\r\n1 &lt;= K &lt;= 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvoid solution(vector<int> &arr, int k){\n\t// write your code here\n}\nint main() {\n\tint n = 0;\n\tcin >> n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tcin >> arr[i];\n\t}\n\tint k = 0;\n\tcin >> k;\n\tsolution(arr, k);\n\treturn 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static void solution(int[] arr, int k){\r\n\t\t//write your code here\r\n\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tint k = scn.nextInt();\r\n\t\tsolution(arr,k);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n9 7 5 3\r\n6","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/BvKv-118twg?end=42","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"7abe74c6-9ce8-4346-a730-360b52b932f6","name":"Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K","slug":"check-if-an-array-can-be-divided-into-pairs-whose-sum-is-divisible-by-k","type":1}],"next":{"id":"ea99999a-e1df-442a-8817-ae454c329d35","name":"Check if an Array can be Divided into Pairs whose Sum is Divisible by K MCQ","type":0,"slug":"check-if-an-array-can-be-divided-into-pairs-whose-sum-is-divisible-by-k-mcq"},"prev":{"id":"75948f9a-ccd6-48e0-8c3f-7845d46040cc","name":"Find Itinerary From Tickets","type":3,"slug":"find-itinerary-from-tickets"}}}` Editor

# Check If An Array Can Be Divided Into Pairs Whose Sum Is Divisible By K

easy

1. You are given an array(arr) of integers and a number K. 2. You have to find if the given array can be divided into pairs such that the sum of every pair is divisible by k.

## Constraints

1 <= N <= 10^6 1 <= arr[i] <= 10^4 1 <= K <= 10^4

## Format

### Input

A number N arr1 arr2.. N numbers A number K

true or false.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 9 7 5 3 6```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}true ```

Question Video

Discussions

Show Discussion

Related Resources 