Last Updated: 26 Nov, 2020

Alpha Pattern

Easy

Problem statement

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
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’, 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.
Constraints:
1 <= T <= 50
1 <= N <= 26

Time Limit: 1 sec

Approaches

01 Approach

The steps are as follows:

  • Since we need to start from the 0th character until the Nth character, we will try thinking forward.
  • We will iterate from i=1 to i=N. For each row in the given matrix, we will perform the following operations:
    • We will iterate through from j=1 to j=i:
      • We will print the characters: ‘A’-1+i while traversing the inner loop.
      • Also, after each iteration of the inner loop completes, we will print a new line.