Skip to content

Commit

Permalink
Create Row with minimum number of 1's
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Apr 22, 2024
1 parent 40b77de commit ba0e620
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Row with minimum number of 1's
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;
}
};

0 comments on commit ba0e620

Please sign in to comment.