-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLastArray.cpp
More file actions
46 lines (36 loc) · 749 Bytes
/
LastArray.cpp
File metadata and controls
46 lines (36 loc) · 749 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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> findTwoElement(vector<int>& arr, int n)
{
// Decreas value
for(int i=0;i<n;i++)
arr[i]--;
// occurance
for(int i=0;i<n;i++)
{
arr[arr[i]%n]+=n;
}
vector<int>ans(2);
for(int i=0;i<n;i++)
{
if(arr[i]/n==2)
ans[0]=i+1;
else if(arr[i]/n==0) // missing number
ans[1]=i+1;
}
return ans;
}
int main()
{
// Find these two numbers Reapeted and Missing
int n;
cout<<"Enter the size of Arrray: ";
cin>>n;
vector<int> arr(n);
cout<<"Enter the Element in Array: ";
for(int i=0; i<n; i++)
cin>>arr[i];
findTwoElement(arr,n);
}