Last Updated: 26 Nov, 2020

Yet another Pattern

Easy

Problem statement

Ninja was playing with her sister to solve a puzzle pattern. However, even after taking several hours, they 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 = 4

****
 ***     
  **
   *
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’.
Output Format:
For each test case, print 'N' strings corresponding to every row in a new line (row elements not separated by space)

Print the output of each test case in a separate line.
Note (c++ ,Python):
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 <= 300

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=0 to i=N. For each row in the given matrix, we will perform the following operations:
    • We will iterate through from j=0 to j=N:
      • We will print the characters: ‘*’ while traversing the inner loop only if j>=i. Otherwise print a space.
      • Also, after each iteration of the inner loop completes, print a new line.