Created
October 7, 2022 20:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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