#include <iostream>
#include<vector>
using namespace std;
void printTwoElements(vector<int>&arr){
int n=arr.size();
//Creating visited vector of size n+1 with
//initial values are false. Note that array
//values will go upto n,that is why we
//we taken the size as n+1
vector<bool>visited(n+1,false);
int repeating =-1;
int missing= -1;
for(int i=0;i<n;i++){
if(visited[arr[i]]){
repeating=arr[i];
}else{
visited[arr[i]]=true;
}
}
for(int i=1;i<=n;i++){
if(!visited[i]){
missing=i;
break;
}
}
cout<<"Repeating: "<<repeating<<endl;
cout<<"Missing: "<<missing<<endl;
}
int main() {
vector<int>arr={7,3,4,5,5,6,2};
printTwoElements(arr);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: