Array ( [0] => [1] => questions [2] => Patterns [3] => Right-Angle-Triangle )
Print the pattern as shown below for all test cases.
First line contains the value N.
Print the output as shown in below examples.
3
1 1 2 1 2 3
5
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
6
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6
Login to see Discussion
Step-i) initialize i to 1
Step-ii) initialize j to 1
Step-iii) print the value of the j and space (" ")
Step-iv) increment j value by one
Step-v) repeat steps iii to iv till j is less than or equal to i
Step-vi)go to next line and increment i value by one
Step-vii)repeat steps ii to vi 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.
Login to see Solution