-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ6
57 lines (44 loc) · 1.02 KB
/
Q6
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:
Given an array A containing 2*N+2 positive numbers, out of which 2*N numbers exist in pairs whereas the other two number occur exactly once and are distinct.
Find the other two numbers. Return in increasing order.
Input Format:
A number n
a1
a2..
n numbers
Output Format
2 Non-repeating number
Constraints
1 <= n <= 10^9
1 <= a1,a2.. <= 10^9
Sample Input
6
23 27 23 17 17 37
Sample Output
27
37
Bug Code:
vector<int> singleNumber(vector<int> nums)
{
// Code here.
map<int,int>mp;
vector<int>ans;
for(int i=0;i<nums.size();i++)
{
mp[nums[i]]++;
}
for(int i=0;i<nums.size();i+=2)
{
if(mp[nums[i]]!=1) //To check if it occurs only once in map
{
ans.push_back(nums[i]);
}
}
for(int i=0;i<2;i++) //To return in increasing order
{
if(ans[0]<ans[1])
{
swap(ans[0],ans[1]);
}
}
return ans;