Skip to main content

Posts

Showing posts with the label Missing Number

Missing Number

Task: Find the missing number from given an array of N numbers from 1 to N. Example: Input: 1 3 1 4 3 Output: 2 Here is the Code: Program in C++: #include <iostream> using namespace std; int main() { //number of test cases int t; scanf("%d\n",&t); while(t--) {     int n;     scanf("%d\n",&n);     int a[n-1],sum=0;     for(int i=0;i<n-1;i++)     {         scanf("%d\n",&a[i]);         sum+=a[i];     }     int sn=(n*(n+1))/2;     cout<<sn-sum<<endl; } return 0; } Here is the Video: