Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Number (Math, bit manipulation) #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions C++/1235.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Missing Number (Math, bit manipulation)


#include <bits/stdc++.h>
using namespace std;

// Function to get the missing number
int getMissingNo(int a[], int n)
{

int total = (n + 1) * (n + 2) / 2;
for (int i = 0; i < n; i++)
total -= a[i];
return total;
}

// Driver Code
int main()
{
int arr[] = { 1, 2, 4, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
int miss = getMissingNo(arr, n);
cout << miss;
}
21 changes: 21 additions & 0 deletions C++/1395.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix

int countNegative(int M[][4], int n, int m)
{
int count = 0;

// Follow the path shown using
// arrows above
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (M[i][j] < 0)
count += 1;

// no more negative numbers
// in this row
else
break;
}
}
return count;
}