Answer to Question #198810 in C++ for adil

Question #198810

Take a Boolean 2D array of 10X 10, where each row is sorted from the user, Find the row with the

maximum number of 1s.


1
Expert's answer
2021-05-27T19:11:13-0400
#include<iostream>
using namespace std;
int row,col;
int index(bool a[],int left,int right){
    if(left<=right){
        int mid=(left+right)/2;
        if((a[mid-1]==0||mid==0)&& a[mid]==1){
                return mid;
        }else{
         if(a[mid]==0){
            return index(a,mid+1,right);
            }else{
                return (a,left,mid-1);
            }
        }



    return -1;
}
 int Row_With_Max_is(bool a[row][col]){
 int max_1=0;
 int max_row_index=0;
 for(int i=0;i<row;i++){
    int idx=index(a[i],0,col-1);
    if(idx==-1)continue;
    int count_1=col-idx;
    if(count_1>max_1){
        max_1=count_1;
        max_row_index=i;
    }

   }

 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog