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





Stars with Numbers

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

Input
4
Output
****1****
***2*2***
**3*3*3**
*4*4*4*4*
Example 3:

Input
5
Output
*****1*****
****2*2****
***3*3*3***
**4*4*4*4**
*5*5*5*5*5*

oops

Login to see Discussion




Approach


Step-i) initialize i to 1
Step-ii)initialize star to 1
Step-iii)print * and increment star by one value
Step-iv) repeat step iii till star is less than or equal to N-i
Step-v) assign 1 to j
Step-vi)if i is equal to i print * and value of i else print * and value of i
Step-vii) if j is equal to i print *
Step-viii)increment j by one value
Step-ix)repeat steps vi to viii till j is less than or equal to i
Step-x)initialize start to 1
Step-xi)print * and increment star by one value
Step-xii)repeat step xi till star is less than or equal to N-i
Step-xiii)go to next line and increment i by one value
Step-xiv) repeat steps ii to xiii 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