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





Triangle with stars

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) assign 1 to i
Step-ii) assign 1 to j
Step-iii) print * and space and then increment the value of j by one
Step-iv) repeat the step iii till j is less than or equal to i
Step-v)go to next line and increment the value of i by one
Step-vi) repeat steps ii to v 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