-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProblem-1.java
64 lines (47 loc) · 1.24 KB
/
Problem-1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @author AkashGoyal
* @date 06/06/2021
*/
/**
--------------------- Problem----------->> Row with max 1s
Problem Link :- https://practice.geeksforgeeks.org/problems/row-with-max-1s0023/1
*/
//Method-1
int rowWithMax1s(int arr[][], int n, int m) {
// code here
int min=m;
int row_with_max_1=-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<min;j++)
{
if(arr[i][j]==1)
{
min=j;
row_with_max_1=i;
}
}
}
return row_with_max_1;
}
// -------------------------------------------------------------------------------------------------------------------------------------------------------
//Method-2 (Optimized)
int rowWithMax1s(int arr[][], int n, int m) {
// code here
int i=0;
int j=m-1;
int row_with_max_1=-1;
while(i<n && j>=0)
{
if(arr[i][j]==1)
{
row_with_max_1=i;
j--;
}
else
{
i++;
}
}
return row_with_max_1;
}