Last Updated: 27 Nov, 2020

Interesting Alphabets

Easy

Problem statement

As a part of its competition, the school will conduct a codeathon, Lock the Code, where it has been given a value, and the participants have to decode it.

The participants are given a value denoting the number of rows in the matrix; they need to print the pattern.

Example : 

For N=5, Pattern:
E
DE
CDE
BCDE
ABCDE 

Among the participants, Ninja is new to programming and doesn’t have much experience; he asks you to solve the problem. Can you help solve this problem?

Input Format:
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’ , denoting the number of rows in the matrix.
Output Format:
For each test case, print 'N' strings denoting 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.
Constraints:
1 <= T <= 50
1 <= N <= 26

Time Limit: 1 sec

Approaches

01 Approach

The idea is to use nested loops in such a way that yields the answer.

 

The steps are as follows:

  • Since we need to start from the Nth character until the 1st character, we will try thinking backward.
  • We will iterate from i = N to i = 1. For each row in the given matrix, we will perform the following operations:
    • We will iterate through from j=i to j=N since we need to print the characters in lexicographical order in each row.
      • So we will add the characters: ‘A’+j-1 into our temporary vector.
      • Also, after each iteration of the inner loop completes, add the temporary vector into our final answer 2D matrix.
  • We will return the matrix as the final answer.