Geeksforgeeks

Timer is Running

Associated Course(s):
Geeks Classes
Geeks Classes DSA- Tutorials

You are given an array of **N+2** integer elements. All elements of the array are in range 1 to N. And all elements occur once except two numbers which occur twice. Find the two repeating numbers.

**Input:**

The first line of the input contains an integer T, denoting the total number of test cases. Then T test cases follow Each test case consists of two lines. First line of each test case contains an integer N denoting the range of numbers to be inserted in array of size N+2. Second line of each test case contains the N+2 space separated integers denoting the array elements.

**Output: **

Print the two elements occuring twice in the array. Order of the two elements must be preserved as in the original list, i.e., print the element which arrives first(2nd time).

**Constraints: **

1 ≤ T ≤ 30

1 ≤ N ≤ 10^{5}

**Example:**

**Input:**

2

4

1 2 1 3 4 3

5

2 4 3 1 2 7 4

**Output:**

1 3

2 4

**Explanation:
Testcase 1: **In the given array, 1 and 3 are repeated two times.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

ykaushik | 261 |

_saswata | 232 |

kirtidee18 | 1057 |

ykaushik | 733 |

aggarwalvatsal5 | 709 |

pmr_3689 | 570 |

harbilassingh | 530 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4823 |

Login to report an issue on this page.