Array ( [0] => [1] => questions [2] => Patterns [3] => Stars-Hallow-Rhombus ) Patterns | Stars Hallow Rhombus | THE INQUISITIVE





Stars Hallow Rhombus

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

Input
4
Output
   *
  * *
 *   *
*     *
*     *
 *   *
  * *
   *
Example 3:

Input
5
Output
    *
   * *
  *   *
 *     *
*       *
*       *
 *     *
  *   *
   * *
    *

oops

Login to see Discussion




Approach


Step-i)initialize i to 1
Step-ii) initialize space to 1
Step-iii) print spaces (" ")
Step-iv)increment space by one value
Step-v)repeat steps iii to iv till space is less than or equal to N-i-1
Step-vi)initialize j to 1
Step-vii)if j is equal to 1 or j is equal to i print * and space else print two spaces (" ")
Step-viii) increment j by one value
Step-ix)repeat steps vii to viii till j is less than or equal to i
Step-x) go to new line and increment i by one value
Step-xi)repeat steps ii to x till i is less than or equal to N
Step-xii)initialize i to N-1
Step-xiii) initialize space to 1
Step-xiv) print spaces (" ")
Step-xv)increment space by one value
Step-xvi)repeat steps xiii to xv till space is less than or equal to N-i-1
Step-xvii)initialize j to 1
Step-xviii)if j is equal to 1 or j is equal to i print * and space else print two spaces (" ")
Step-xix) increment j by one value
Step-xx)repeat steps xviii to xix till j is less than or equal to i
Step-xxi) go to new line and decrement i by one value
Step-xxii)repeat steps xiii to xxi till i is greater than or equal to 1

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