All Problems

Problem title

Difficulty

Avg time to solve

LCA of three Nodes

Easy

20 mins

Sum Of Infinite Array

Moderate

35 mins

Pair Sum

Easy

15 mins

Sum or Product

Easy

15 mins

Reverse The Array

Easy

15 mins

Flower Shop

Easy

--

Find Duplicate in Array

Easy

15 mins

Sort 0 1 2

Easy

22 mins

Two Sum

Easy

10 mins

Beautiful String

Easy

18 mins

Problem

Submissions

309

Avg. time to solve

10 min

Success Rate

90%

Problem Statement

```
We cannot use the element at a given index twice.
```

```
Try to do this problem in O(N) time complexity.
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains two single space-separated integers ‘N’ and ‘Target’ denoting the number of elements in an array and the Target, respectively.
The second line of each test case contains ‘N’ single space-separated integers, denoting the elements of the array.
```

```
For each test case, print a single line containing space-separated integers denoting all pairs of elements such that they add up to the target. A pair (a, b) and (b, a) is the same, so you can print it in any order.
Each pair must be printed in a new line. If no valid pair exists, print a pair of (-1, -1). Refer to sample input/output for more clarity.
```

```
You do not need to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 100
1 <= N <= 5000
-10 ^ 9 <= TARGET <=10 ^ 9
-10 ^ 9 <= ARR[i] <=10 ^ 9
Where 'T' denotes the number of test cases, 'N' represents the size of the array, 'TARGET' represents the sum required, and 'ARR[i]' represents array elements.
Time Limit: 1 sec.
```

```
2
4 9
2 7 11 13
5 1
1 -1 -1 2 2
```

```
2 7
-1 2
-1 2
```

```
For the first test case, we can see that the sum of 2 and 7 is equal to 9 and it is the only valid pair.
For the second test case, there are two valid pairs (-1,2) and (-1,2), which add up to 1.
```

```
1
4 16
2 7 11 13
```

```
-1 -1
```

Java (SE 1.8)

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Theme

Solution submission not allowed

Save Code

Reset Code