VOOZH about

URL: https://www.geeksforgeeks.org/computer-science-fundamentals/hollow-half-pyramid-pattern-using-numbers/

⇱ Hollow Half Pyramid Pattern Using Numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hollow Half Pyramid Pattern Using Numbers

Last Updated : 20 Mar, 2024

A hollow half-pyramid pattern using numbers is a type of pattern that seems like a pyramid shape mostly it is considered a star pattern but here we will be creating using numbers. 

👁 Hollow half pyramid pattern using numbers
Hollow half-pyramid pattern using numbers

Program to print the following pattern of a half pyramid for N.

Example: 

Input: N = 5
1
1 2
1 3
1 4
1 2 3 4 5


Below is the implementation of the above approach:


Output
1 
1 2 
1 3 
1 4 
1 2 3 4 5 

Time complexity O(N2

Reason: we are looping through the rows and columns of the pattern.


Space complexity O(1)

Reason: This algorithm does not require any additional space.


Hollow Inverted Half Pyramid Pattern using numbers

Printing an Inverted pyramid of a pattern is mostly the same as printing the pyramid normally just changes in a few conditions and we are all done. Let us check the code.

Example: 

input: N = 6
1 2 3 4 5 6
2 6 
3 6
4 6
5 6
6



Output
1 2 3 4 5 6 
2 6 
3 6 
4 6 
5 6 
6 

Time complexity O(N2

Reason: we are looping through the rows and columns of the pattern.


Space complexity O(1)

Reason: This algorithm does not require any additional space.


Comment