Last Updated: 27 Nov, 2020

Binary Pattern

Easy
Asked in companies
SAP LabsInca Infotech Technologies Private Limited

Problem statement

You have been given an input integer 'N'. Your task is to print the following binary pattern for it.

Example

Pattern for 'N' = 4

1111
000
11
0

The first line contains 'N' 1s. The next line contains 'N' - 1 0s. Then the next line contains 'N' - 2 1s and so on.

Input format :
The first line of input contains an integer 'T' that denotes the number of test cases.

The first line of each test case contains a single integer 'N'.
Output format :
For each test case, print 'N' lines containing the pattern, each of the 'I-th' lines should contain 'N' - 'I' + 1 number depending on the 'I' value. 
Constraints :
1 <= T <= 10
1 <= N <= 10^3

Time Limit: 1 sec

Approaches

01 Approach

In the pattern, every even-numbered line is filled with 0's, and the odd-numbered line is filled with 1's and we have total N lines. 

We can run a for loop from 0 to N for each line and inside that for loop we can run again another for loop till the N - i times where ‘i’ is the line number. respective of line number we can print the 0 or 1.