can I do this? Binary Search : Median of two sorted arrays of different sizes. for(int i=0; i> Algorithms >> Interview >> Java If you want someone to read your code, please put the code inside
tags. After checking all entries, we can update the matrix according the the first row and the first column. for(int i = 0 ; i < numColumns ; i++) { Given a m * n matrix mat of ones (representing soldiers) and zeros (representing civilians), return the indexes of the k weakest rows in the matrix ordered from the weakest to the strongest. Set rows = new HashSet(); int numColumns = array[0].length; } //set first column and row so after whole matrix will be marked by 0s?? To reduce the space required, we can use the matrix itself to store the flags for each row and column if they need to set to 0. } if(j >= m[0].length) } { j = 0; if have zero at 0:0, 0column and 0row will be marked zero.? First column contains zero = false; Step 2: use first row and column to mark zero row and column. eval(ez_write_tag([[580,400],'programcreek_com-medrectangle-4','ezslot_2',137,'0','0'])); Specifically, given, the following matrix } historyRow[i] = true; for(int row : rows) { The zero() is an inbuilt method in Ruby returns an N x M zero matrix where each element is zero.. Syntax:, M). matrix[k][j] = 0; Then iterate through the matrix if you find zero mark that row and column to zero in boolean matrix: At the end of first iteration we have marked all the rows or columns that should be marked to zero. If it’s zero, for example, if matrix[i][j] is zero, we can update matrix[i][0] and matrix[0][j] to zero. { } i += 1; eval(ez_write_tag([[728,90],'tutorialcup_com-banner-1','ezslot_7',623,'0','0']));So we can get soldiersCount by score/rows, and get rowIndex by score % rows. This problem should be solved in place, i.e., no other array should be used. boolean[] historyRow = new boolean[n]; System.out.print(array[i][j] + " "); { i.e. for(int i=1; i