File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments