Array ( [0] => [1] => questions [2] => Basic [3] => Triangle-with-Alphabets ) Patterns | Triangle with Alphabets | THE INQUISITIVE





Triangle with Alphabets

LEVEL:Beginner

Description

Print the pattern as shown below for all test cases.

Input Format

First line contains the value N.

Output Format

Print the output as shown in below examples.


Example 1:

Input
3
Output
A
ABA
ABCBA
Example 2:

Input
4
Output
A
ABA
ABCBA
ABCDCBA
Example 3:

Input
5
Output
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA

oops

Login to see Discussion




Approach


Step-i)assign 65 to ch as 65 is the ascii value of the character A
Step-ii) assign 1 to i
Step-iii) assign 1 to j
Step-iv)print the ch and space and then increment the ch and j by one value
Step-v) repeat step iv till j is less than or equal to i
Step-vi)decrement the value of ch
Step-vii)assign 1 to k
Step-viii) print ch and space then decrement the value of ch and increment the value of k by one
Step-ix)repeat step viii till k is less than i
Step-x) assign 65 to ch , go to next line and increment i by one value
Step-xi)repeat steps iii to x till i is less than or equal to N

Time Complexity: O(n^2)
Space Complexity: O(1)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution