Skip to content

Instantly share code, notes, and snippets.

@webber2408
Created October 7, 2022 20:41
Show Gist options
  • Save webber2408/065f2d4ead45c7b1c4c629fd0da7ce8b to your computer and use it in GitHub Desktop.
Save webber2408/065f2d4ead45c7b1c4c629fd0da7ce8b to your computer and use it in GitHub Desktop.
Approach-1) Finding Missing & Repeating Number - Using extra array and index setting algorithm
#include <bits/stdc++.h>
#include <bits/stdc++.h>
pair<int,int> missingAndRepeating(vector<int> &arr, int n)
{
int mp[n+1] = {0};
for(int i=0; i<n; i++)
mp[arr[i]]++;
int missing = -1, repeating = -1;
for(int i=1; i<=n; i++){
if(mp[i] == 0) missing = i;
else if(mp[i] > 1) repeating = i;
}
return make_pair(missing, repeating);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment