In a party, Ninja was playing with his cousins to solve an alphabet pattern problem given by their uncle. However, even after taking several hours, the cousins could not solve the problem.
A value of ‘N’ is given to them, and they are asked to solve the problem. Since they are stuck for a while, they ask you to solve the problem. Can you help solve this problem?
Example :
Pattern for N = 3
A
BB
CCC
The first line of input contains an integer ‘T,’ denoting the number of test cases. The test cases follow.
The first line of each test case contains a single integer ‘N’, given to Ninja and his cousins.
Output Format:
For each test case, print every row in a new line (row elements not separated by space)
Print the output of each test case in a separate line.
Note:
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 26
Time Limit: 1 sec
2
3
2
A
BB
CCC
A
BB
In the first test case, the value of ‘N’ is 3, so print the three rows from 1 to ‘3’ where each row print the ith Alphabet ‘i’ times where ‘i’ ranges from 1 to 3. Hence the answer is [“A”,”BB”,”CCC”].
In the second test case, value of ‘N’ is 2, so print the two rows from 1 to 2 where each row print the ith Alphabet ‘i’ times where ‘i’ ranges from 1 to 2. Hence the answer is [“A”,”BB”].
Sample Input 2:
2
4
5
A
BB
CCC
DDDD
A
BB
CCC
DDDD
EEEEE
The idea is to use nested loops in such a way that yields the answer.
The steps are as follows:
O(N^2), where N is the number of rows in the matrix.
We are traversing each row of the matrix that takes O(N) time complexity, and inside each loop, we are using an additional loop twice between the columns, which takes extra time (N). Hence the overall time complexity is O(N^2).
O(1), no extra space required.
As we are not using any extra space. Hence, the overall space complexity is O(1).