File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #https://practice.geeksforgeeks.org/problems/row-with-max-1s0023/1#
2
+
3
+ #Steps :
4
+
5
+ # 1 . Initialize the count of ones in a row as max_ones_row = -1
6
+ # 2 . Initialize the max count of 1's as max_ones = 0
7
+ # 3 . Iterate through each row and find the ones count
8
+ # 4 . Compare the max_ones with max_ones_row in each row and store the updated count in max_ones_row
9
+
10
+ class Solution :
11
+
12
+ def rowWithMax1s (self ,arr , n , m ):
13
+ # code here
14
+ j = m - 1
15
+ max_ones = 0
16
+ max_ones_row = - 1
17
+ for i in range (0 , n ):
18
+ ones = self .countones (arr [i ])
19
+ if ( ones > max_ones ):
20
+ max_ones = ones
21
+ max_ones_row = i
22
+
23
+
24
+ return max_ones_row
25
+
26
+ def countones (self , a ):
27
+ count = a .count (1 )
28
+ return count
29
+
30
+ #{
31
+ # Driver Code Starts
32
+ #Initial Template for Python 3
33
+
34
+ if __name__ == '__main__' :
35
+ tc = int (input ())
36
+ while tc > 0 :
37
+ n , m = list (map (int , input ().strip ().split ()))
38
+
39
+ inputLine = list (map (int , input ().strip ().split ()))
40
+ arr = [[0 for j in range (m )] for i in range (n )]
41
+
42
+ for i in range (n ):
43
+ for j in range (m ):
44
+ arr [i ][j ] = inputLine [i * m + j ]
45
+ ob = Solution ()
46
+ ans = ob .rowWithMax1s (arr , n , m )
47
+ print (ans )
48
+ tc -= 1
49
+
50
+ # } Driver Code Ends
You can’t perform that action at this time.
0 commit comments