Problem of the day
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.
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.
1 <= T <= 10
1 <= N <= 10^3
Time Limit: 1 sec
2
1
2
1
11
0
2
3
5
111
00
1
11111
0000
111
00
1
Can you use for loops?
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.
O(N^2) where N is the input integer.
As we are running 2 loops from 0 to N, there will be N^2 steps hence overall time complexity will be O(N^2).
O(1)
There will not be any extra space usage.