diff --git a/C++/1235.cpp b/C++/1235.cpp new file mode 100644 index 0000000..5f9cbab --- /dev/null +++ b/C++/1235.cpp @@ -0,0 +1,24 @@ +// Missing Number (Math, bit manipulation) + + +#include +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; +} \ No newline at end of file diff --git a/C++/1395.cpp b/C++/1395.cpp new file mode 100644 index 0000000..2b5702b --- /dev/null +++ b/C++/1395.cpp @@ -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; +} \ No newline at end of file