0 votes 0 votes If we have a n*n Bit-Array in which we have only 1's and 0's filled . Constraint is that in every row , 0 comes before 1 , so how to find the index of the row which has maximum no of 1's Algorithms algorithms + – radha gogia asked Jul 26, 2018 radha gogia 286 views answer comment Share Follow See 1 comment See all 1 1 comment reply MiNiPanda commented Jul 26, 2018 reply Follow Share #include<stdio.h> int main() { int n,i,j,index,a[50][50],row; scanf("%d",&n); index=n; // Index is a variable assigned with value n for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i][j]==1) // If 1st 1 appears at jth column in the i th row it means the row will not // have any 0's appearing after this 1 (as per the constraint) //If 1st 1 appears at the 0th column that means the row is full of 1's --> n 1's // If 1st 1 appears at the 1th column that means the row has 1's starting from 1th column--> (n-1) 1's // This means as the value of column is less, more no. of 1's are there in that row { if(j<index) { // we compare the column with index, if it is less means this row has more no. of 1's than any previous row index=j; //update index row=i ; //remember the row } break; // No need to see for further 1's in that row because according to the constraint there will be no 0's after 1's } } printf("\n %d %d",index,row); } printf("\nAns %d",row); } 1 votes 1 votes Please log in or register to add a comment.