Problem title
Difficulty
Avg time to solve

Bob’s Path Task!
Easy
15 mins
Postorder Successor
Moderate
15 mins
K - Sum Path In A Binary Tree
Moderate
35 mins
K Turns Allowed
Moderate
25 mins
Special Sum of Array
Easy
15 mins
Interesting Alphabets
Easy
10 mins
Chocolate Fest
Moderate
25 mins
Ninja and power of 2
Easy
15 mins
Starfield
Easy
15 mins
Play with Pattern
Easy
20 mins
6

Starfield

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
80%

Problem Statement

Ninja loves playing with characters. So one day, he wants to arrange a few characters in the ‘N’ number of rows. The pattern consists of a left triangle a right triangle and a mirror image of the top part below.

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:
*   *
 * *
* * *
 * *
*   *
Input Format:
The first line contains ‘T’, denoting the number of test cases.

Each test case contains a single integer ‘N’, denoting the number of rows.
Output Format:
For each test case, print the 'N' strings denoting the required pattern in the following ‘N’ lines.
Note:
You are not required to print the expected output; it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= N <= 10^3

Time Limit: 1 sec
Sample Input 1 :
2
3
4
Sample Output 1 :
      *   *
       * *
      * * *
       * *
      *   *

     *     *
      *   *
     * * * *
      * * *
     * * * *
      *   *
     *     *
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 :
  *           *
   *         *
  * *       * *
   * *     * *
  * * *   * * *
   * * * * * *
  * * * * * * *
   * * * * * *
  * * *   * * *
   * *     * *
  * *       * *
   *         *
  *           *

      * *
       *
      * *
Reset Code
Full screen
copy-code
Console