Problem of the day
You are given an integer 'N'. Your task is to print the following pattern for the given N number of rows.
For Example: Pattern for N = 4
1
11
111
1111
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain an integer ‘N’ that is the total number of rows.
Output Format:
For each test case, print the pattern of N lines.
Output for every test case will be printed in a separate line.
1 <= T <= 10
1 <= N <= 10^3
Time Limit: 1 sec
2
1
2
1
1
11
2
3
4
1
11
111
1
11
111
1111
Try to make relation between number of columns in particular row.
The basic idea of this approach is to print the pattern row-wise. For each row, a pattern is observed: 1 is printed 1 time in the 1st row, 2 times in the 2nd row, 3 times in the 3rd row, and so on. So, a pattern is observed that the number of rows determines how many times 1 is printed in each row.
Here is the algorithm:
O(N^2), where N is the number of rows.
Because we are using two loops, the outer loop runs for the number of rows given to us, and the inner loop prints the value for every column. Hence the time complexity is O(N^2).
O(1),
Because we are not using any extra space for finding our answer.