-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ7
More file actions
55 lines (38 loc) · 766 Bytes
/
Q7
File metadata and controls
55 lines (38 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Problem statement:
1. You are given an array of length n containing numbers from 1 to n.
2. One number is present twice in array and one is missing.
3. You have to find these two numbers.
Input Format:
A number n
a1
a2..
n numbers
Output Format:
Missing number
Repeating Number
Constraints:
1 <= n <= 10^9
1 <= a1,a2.. <= 10^9
Sample Input
7
1
3
4
5
1
6
2
Sample Output:
Missing Number -> 7
Repeating Number -> 1
Bug Code:
int *findTwoElement(int *arr, int n) {
int *ans = new int[2];
vector<int> freq(n+1,0);
for(int i = 0; i < n; i++)
freq[arr[i]];
for(int i = 1; i <= n; i++){
if(freq[i] > 1) ans[0] = i;
if(freq[i]) ans[1] = i;
}
return ans;