Input: N = 2
Output:1 1 1 1
Sum of 0th row = 1 + 1 = 2 (Prime number)
Sum of 1st row = 1 + 1 = 2 (Prime number)
Sum of 0th column = 1 + 1 = 2 (Prime number)
Sum of 1st column = 1 + 1 = 2 (Prime number)
Input: N = 4
1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1
Approach: Follow the steps below to solve the problem:
- Initialize a Binary matrix, say mat of size N * N.
- Update all possible values of mat[i][i] to 1.
- Update all possible values of mat[i][N – i -1] to 1.
- If N is an odd number then update the value mat[N / 2] and mat[N / 2] to 1.
Below is the implementation of the above approach.
1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1
Time Complexity: O(N2)
Auxiliary Space: O(N2)
- Program to find the Sum of each Row and each Column of a Matrix
- Minimum element of each row and each column in a matrix
- Construct a matrix such that union of ith row and ith column contains every element from 1 to 2N-1
- Sum of matrix in which each element is absolute difference of its row and column numbers
- Sum of matrix element where each elements is integer division of row and column
- Maximum sum of a Matrix where each value is from a unique row and column
- Minimum operations required to make each row and column of matrix equals
- Print an N x M matrix such that each row and column has all the vowels in it
- Count of ways to generate a Matrix with product of each row and column as 1 or -1
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Construct a square Matrix whose parity of diagonal sum is same as size of matrix
- Find if a binary matrix exists with given row and column sums
- Count positions in Binary Matrix having equal count of set bits in corresponding row and column
- Count 1s in binary matrix having remaining indices of its row and column filled with 0s
- Construct a Matrix such that each cell consists of sum of adjacent elements of respective cells in given Matrix
- Check whether row or column swaps produce maximum size binary sub-matrix with all 1s
- Leftmost Column with atleast one 1 in a row-wise sorted binary matrix
- Leftmost Column with atleast one 1 in a row-wise sorted binary matrix | Set 2
- Find sum of all elements in a matrix except the elements in row and/or column of given cell?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.