Skip to content

Commit

Permalink
Merge pull request #332 from TesseractCoding/master
Browse files Browse the repository at this point in the history
mpr
  • Loading branch information
JayantGoel001 authored May 25, 2021
2 parents f65f99f + 75e71b2 commit c4c5165
Show file tree
Hide file tree
Showing 5 changed files with 5,203 additions and 0 deletions.
2 changes: 2 additions & 0 deletions C-Plus-Plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
- [First Fit memory Allocation](ds/first_fit.cpp)
- [Best Fit memory Allocation](ds/best_fit_memory.cpp)
- [Worst Fit memory Allocation](ds/worst_fit_memory.cpp)
- [Row with max 1s ](ds/Row_with_max_1s.cpp)
- [Max rectangle](ds/Max_rectangle.cpp)
- [Palindrome checker using doubly linked list](ds/palindrome_doubly_linked_list.cpp)
- [BFS of Binary Tree](ds/BFS_Binary_Tree.cpp)
Expand All @@ -283,6 +284,7 @@
- [Construct Binary Tree from Inorder and Postorder](ds/BinaryTreeFromInorderPostorder.cpp)
- [Insertion Sort On Linked List](ds/insertion_sort_on_linked_list.cpp)


## Graphs

- [Adjacency List Representation](graphs/Adjacency_List.cpp)
Expand Down
87 changes: 87 additions & 0 deletions C-Plus-Plus/ds/Row_with_max_1s.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Row with max 1s = Here given a boolean 2D array where each row is sorted, so here find which first row contain maximum number of 1's.
ALGORITHM:
* 1st take value row and col by user input where row = No of row, col = No of column and then we create a 2D vector (matrix)
* Then we created a function find_Max1s
* find_Max1s = 1. 1st initialize i, j=col-1, index = -1
2. for i=0 to row
while j>=0
if a[i][j]==1
index=i
j--
else
break
3. return index
*/

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

// finding row with max 1s
int find_Max1s(vector<vector<int>> a, int row, int col)
{
int i, j = col - 1, index = -1;
for (i = 0; i < row; i++)
{
while (j >= 0)
{
//when a[i][j]==1 then j decrement
if (a[i][j] == 1)
{
//here store the row index i
index = i;
j--;
}
else
break;
}
}
return index;
}

int main()
{
int row, col;
cout << "No of row : ";
cin >> row;
cout << "No of column : ";
cin >> col;
vector<vector<int>> a(row, vector<int>(col));
cout << "Taking the matrix : " << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cin >> a[i][j];
}
}
int ans = find_Max1s(a, row, col);
cout << "Output : ";
cout << ans << endl;
return 0;
}

/*
INPUT:
No of row : 5
No of column : 5
Taking the matrix :
0 0 0 1 1
1 1 1 0 1
1 1 0 0 0
0 0 0 0 0
1 1 1 0 0
Output : 1
Time Complexity : O(row x col)
Space Complexity : O(1)
*/






2 changes: 2 additions & 0 deletions Python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@
- [Churn Risk Score Prediction](ml/Churn_Risk_Score_Prediction.ipynb)
- [Decision Tree](ml/DecisionTree_From_Scratch.ipynb)
- [E-Mail Classification](ml/E-Mail_Classification.ipynb)
- [Flight Delay Prediction](ml/Flight_Delay_Predictions.ipynb)
- [Ice Cream Revenue Prediction](ml/Ice_Cream_Revenue_Prediction.ipynb)
- [Income Classification](ml/Income_Classification.ipynb)
- [Iris Classifier using Keras](ml/Iris_Classifier_using_Keras.ipynb)
- [K Nearest Neighbor](ml/K_nearest_neighbors.ipynb)
- [Linear Regression](ml/Linear_Regression.ipynb)
Expand Down
Loading

0 comments on commit c4c5165

Please sign in to comment.