-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Row with minimum number of 1's
- Loading branch information
1 parent
40b77de
commit ba0e620
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//Row with minimum number of 1's | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class GFG { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(read.readLine()); | ||
|
||
while(t-- > 0) { | ||
String s[] = read.readLine().split(" "); | ||
int N = Integer.parseInt(s[0]); | ||
int M = Integer.parseInt(s[1]); | ||
int A[][] = new int[N][M]; | ||
|
||
for(int i = 0; i < N; i++) { | ||
String S[] = read.readLine().split(" "); | ||
|
||
for(int j = 0; j < M; j++) { | ||
A[i][j] = Integer.parseInt(S[j]); | ||
} | ||
} | ||
|
||
Solution ob = new Solution(); | ||
System.out.println(ob.minRow(N, M, A)); | ||
} | ||
} | ||
} | ||
|
||
class Solution { | ||
int minRow(int n, int m, int a[][]) { | ||
int minOnes = m, min_row = 1; | ||
|
||
for(int i = 0; i < n; i++) { | ||
int ones = 0; | ||
|
||
for(int j = 0; j < m; j++) { | ||
|
||
if(a[i][j] == 1) { | ||
ones++; | ||
} | ||
} | ||
|
||
if(ones < minOnes) { | ||
minOnes = ones; | ||
min_row = i + 1; | ||
} | ||
} | ||
|
||
return min_row; | ||
} | ||
}; |