`{"id":"5aed1bbc-1829-4c49-935b-b83c01bc0f80","name":"Find Pair With Given Difference","description":"1. Given an array arr of size n, you need to write a program to find if there exists a pair of elements in the array whose difference is equals to target.\r\n2. If there exists such a pair print it, otherwise print -1.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= target &lt;= 10^4\r\n1 &lt;= arr[i], n &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<algorithm>\n\nusing namespace std;\n\nvoid findPair(vector<int> &arr,int target) {\n //write your code here\n}\n\nint main() {\n int n;\n cin>>n;\n vector<int>arr(n);\n for(int i=0; i < n;i++) {\n cin>>arr[i];\n }\n int target;\n cin>>target;\n findPair(arr,target);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n\r\n public static void findPair(int[]arr,int target) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for(int i=0; i < n;i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int target = scn.nextInt();\r\n findPair(arr,target);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n5 2 3 80 5 20\r\n78","sampleOutput":"2 80","questionVideo":"https://www.youtube.com/embed/XGrXiVi7Ces","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"f89cce46-500a-4cd3-a452-b9e76b30ddd2","name":"Find Pair With Given Difference","slug":"find-pair-with-given-difference","type":1}],"next":{"id":"820279c0-b2bc-4961-ba32-e1b570f16f18","name":"Find Pair With Given Difference Medium","type":3,"slug":"find-pair-with-given-difference-medium"},"prev":{"id":"9b862a1e-8e32-415f-9790-6317c6412b69","name":"Union Of Two Sorted Arrays Medium MCQ","type":0,"slug":"union-of-two-sorted-arrays-medium-mcq"}}}`

# Find Pair With Given Difference

1. Given an array arr of size n, you need to write a program to find if there exists a pair of elements in the array whose difference is equals to target. 2. If there exists such a pair print it, otherwise print -1.

`{"id":"5aed1bbc-1829-4c49-935b-b83c01bc0f80","name":"Find Pair With Given Difference","description":"1. Given an array arr of size n, you need to write a program to find if there exists a pair of elements in the array whose difference is equals to target.\r\n2. If there exists such a pair print it, otherwise print -1.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= target &lt;= 10^4\r\n1 &lt;= arr[i], n &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<algorithm>\n\nusing namespace std;\n\nvoid findPair(vector<int> &arr,int target) {\n //write your code here\n}\n\nint main() {\n int n;\n cin>>n;\n vector<int>arr(n);\n for(int i=0; i < n;i++) {\n cin>>arr[i];\n }\n int target;\n cin>>target;\n findPair(arr,target);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n\r\n public static void findPair(int[]arr,int target) {\r\n //write your code here\r\n }\r\n\r\n public static void main(String[]args) {\r\n\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for(int i=0; i < n;i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int target = scn.nextInt();\r\n findPair(arr,target);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n5 2 3 80 5 20\r\n78","sampleOutput":"2 80","questionVideo":"https://www.youtube.com/embed/XGrXiVi7Ces","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"f89cce46-500a-4cd3-a452-b9e76b30ddd2","name":"Find Pair With Given Difference","slug":"find-pair-with-given-difference","type":1}],"next":{"id":"820279c0-b2bc-4961-ba32-e1b570f16f18","name":"Find Pair With Given Difference Medium","type":3,"slug":"find-pair-with-given-difference-medium"},"prev":{"id":"9b862a1e-8e32-415f-9790-6317c6412b69","name":"Union Of Two Sorted Arrays Medium MCQ","type":0,"slug":"union-of-two-sorted-arrays-medium-mcq"}}}`

Editor

# Find Pair With Given Difference

medium

1. Given an array arr of size n, you need to write a program to find if there exists a pair of elements in the array whose difference is equals to target. 2. If there exists such a pair print it, otherwise print -1.

## Constraints

1 <= target <= 10^4 1 <= arr[i], n <= 10^5

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## 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;}6 5 2 3 80 5 20 78```

### 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;}2 80`

Question Video

Discussions

Show Discussion

Related Resources