Given an N by M array, mark all elements of the array that are in the same column and row as a ‘0’ element as '0’; Example: Input: 1 2 3 4 1 2 3 4 1 2 0 4 1 2 3 4 Output: 1 2 0 4 1 2 0 4 0 0 0 0 1 2 0 4 void MarkRowColumnZero(int arr[N][M]) { bitset<N> zero_row = { 0 }; bitset<M> zero_column = { 0 }; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (arr[i][j] == 0) { zero_row[i] = 1; zero_column[j] = 1; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (zero_row[i]) arr[i][j] = 0; else if (zero_column[j]) arr[i][j] = 0; } } } |