×

BINMT – Editorial

Author: Md Shahid
Tester: Arkapravo Ghosh
Editorialist: Arkapravo Ghosh

SIMPLE

PREREQUISITES:

2D Array, Logical AND

PROBLEM:

Given a N* N matrix A containing only 0’s and 1’s, your task is to AND every element of the matrix with the elements of its corresponding row and column and output the resulting matrix.

EXPLANATION:

The task is to AND every element of the matrix with the elements of its corresponding row and column. So, it is very clear that if a an element is 0, then the result of ANDing the elements of its corresponding row or column will be 0 also (Recall (0 AND something) = 0). So we can keep two arrays, one corresponding each column and one corresponding each row. Initially we set all the elements of the array to false. Now, if we find a 0, then we will set the corresponding row of the 0 in the row array to true and do the same with the column array also. So, now when printing the matrix, if we see that the corresponding row or column array index has a true value, then a 0 was present in the corresponding row or column, thus making the result of the AND to 0.

You can find the author's and editorialist's solution below for further implementation details.

AUTHOR'S AND EDITORIALIST'S SOLUTIONS:

Author's solution can be found here.
Editorialist’s solution can be found here

This question is marked "community wiki".

3436
accept rate: 21%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,191
×105
×94
×83
×8
×3

question asked: 25 Sep '18, 22:24

question was seen: 142 times

last updated: 11 Oct '18, 17:13