Skip to content

Commit 22b7a78

Browse files
authored
Add files via upload
1 parent 872c3a9 commit 22b7a78

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Practice8.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package BinarySearch;
2+
3+
import java.util.Scanner;
4+
5+
public class Practice8 {
6+
7+
public static int maxi(int arr[],int target){
8+
int low = 0;
9+
int high = arr.length - 1;
10+
int ind = arr.length;
11+
12+
while(low <= high){
13+
int mid = (low + high)/2;
14+
15+
if(arr[mid] >= target){
16+
ind = mid;
17+
high = mid - 1;
18+
}
19+
else{
20+
low = mid + 1;
21+
}
22+
}
23+
return ind;
24+
}
25+
26+
public static int maxiOnes(int arr[][] , int n , int m){
27+
int maxCount = - 1;
28+
int maxIndex = - 1;
29+
30+
for(int i = 0; i < n; i++){
31+
int count = m - maxi(arr[i], 1);
32+
33+
if(count > maxCount){
34+
maxCount = count;
35+
maxIndex = i;
36+
}
37+
}
38+
return maxIndex;
39+
}
40+
41+
42+
public static void main(String[] args) {
43+
44+
Scanner sc = new Scanner(System.in);
45+
46+
int n = sc.nextInt();
47+
int m = sc.nextInt();
48+
49+
int arr[][] = new int[n][m];
50+
51+
for(int i = 0; i < n; i++){
52+
for(int j = 0; j < m ; j++){
53+
arr[i][j] = sc.nextInt();
54+
}
55+
}
56+
57+
System.out.println(maxiOnes(arr, n, m));
58+
}
59+
}

0 commit comments

Comments
 (0)