Created
August 19, 2020 12:21
-
-
Save iamprayush/97efb9deb7afa01b8c04b9cf5934fab9 to your computer and use it in GitHub Desktop.
Find Missing And Repeating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for _ in range(int(input())): | |
n = int(input()) | |
arr = input().split() | |
for i in range(n): | |
arr[i] = int(arr[i]) | |
repeat, missing = -1, -1 | |
for i in range(n): | |
if arr[abs(arr[i]) - 1] < 0: | |
repeat = abs(arr[i]) | |
else: | |
arr[abs(arr[i]) - 1] *= -1 | |
for i in range(n): | |
if arr[i] > 0: | |
missing = i + 1 | |
print(repeat, missing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment