Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Ninja and characters

Easy
0/40
Average time to solve is 15m
18 upvotes
Asked in companies
Innostax Software LabsWatchGuard TechnologiesDTCC

Problem statement

Ninja loves playing with characters. So one day, he wants to arrange a few characters in the ‘N’ number of rows. The first row contains 1 character, the second row has two characters, the third row has 3 characters, and so on.

Ninja starts placing characters in increasing order, with an absolute difference of 1, starting from A and can go up to Z only.

You are given an integer ‘N’ denoting the given number of rows. Can you print the pattern Ninja wants to create?

Pattern for N = 3

A
BB
CCC
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 10
1 <= N <= 26

Time Limit: 1 sec
Sample Input 1 :
2
3
4
Sample Output 1 :
A
BB
CCC
A
BB
CCC
DDDD
Explanation for Sample Input 1 :
In the first test case, we are required to create a pattern consisting of 3 lines. First-line contains ‘A’. From the second line, we have to place a character one more than the previous value. So we place ‘B’.We put 2 ‘B’ and move to the following line because this line will contain only 2 elements. In the following line, we have to place 3 characters, so we place 3 ‘C’.

 In the second test case, we are required to create a pattern consisting of 4 lines. First-line contains ‘A’. From the second line, we have to place a character one more than the previous value. So we place ‘B’.We put 2 ‘B’ and move to the following line because this line will contain only 2 elements. In the following line, we have to place 3 characters, so we place 3 ‘C’.In the next line, there will be 4 ‘D’.   
Sample Input 2 :
2
7
2
Sample Output 2 :
A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGGG
A
BB
Full screen
Console