Ninja wants to build a number pattern for the given integer.
For example, If the given integer ‘N’ is 4
Pattern:
1
23
345
4567
Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains one integer, ‘N’, denoting the number of rows.
Output Format:
The output of each test case will be 'N' strings denoting the pattern printed for the given ‘N’ number of rows.
Output for each test cases will be printed on a separate line
Note:
You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N <= 100
Where ‘T’ is the total number of test cases, ‘N’ is the number of rows in each query.
2
3
5
1
23
345
1
23
345
4567
56789
Test case 1:
In the first test case, as ‘N’ is equal to 3, We will have to print three lines. Each line starts with its row number and prints next (row number - 1) numbers.
As in this example:
The first row starts with “1” as the row number is one and print only “1” as “row number - 1“ is 0
For the second row, it starts with two and prints one more number that is 3.Similarly, the third line starts with 3 and ends at 5.
Test case 2:
In the second test case, as “N” is equal to “5”, We will have to print five lines. Each line starts with its row number and prints next (row number - 1) numbers.
As in this example:
The first row starts with 1 as the row number is one and print only 1 as “row number - 1“ is 0
The second row starts with two and prints one more number that is “3”.
Similarly, the 5th row starts with “5” and ends at “9”.
1
1
1
Test case 1:
As ‘N’ is equal to ‘1’, we just need to print one line i.e 1.
Observe the row number carefully.
We can see here that we need to print the “N” number of rows for each input.
Each row should start with the corresponding row number, and we need to print the next continuous (row number -1) numbers.
We can take two for loops here in which our first loop will traverse the number of rows.
We will create a array of strings “arr” that will store the elements and return the function array.
In our nested loop, we need to start printing “i” particular numbers beginning with “i” where “i” is the counter for the other loop. We can keep a local variable that will store the value of “i” outside the nested loop each time and store the next “i” integers in the string inside the loop.
O(N ^ 2) where N is the number of rows of the array.
We are traversing “N” rows in each test case. In each row, we are printing “ row number elements”. So our nested loop with the other loop will run (N * (N+1))/2 times. Hence the overall time complexity is O(N ^ 2).
O(N ^ 2) where N is the number of rows of the array
As we are returning an array of size “N” containing “N string” each of size beginning from “1” to “N”.