VOOZH about

URL: https://www.geeksforgeeks.org/dsa/hour-glass-pattern/

⇱ Hour-glass Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Hour-glass Pattern

Last Updated : 17 Feb, 2023

Given positive integer n, print numeric pattern in form of an hourglass.
Examples : 
 

Input : rows_no = 7
Output :

1 2 3 4 5 6 7
 2 3 4 5 6 7
 3 4 5 6 7
 4 5 6 7
 5 6 7
 6 7 
 7
 6 7
 5 6 7
 4 5 6 7
 3 4 5 6 7
 2 3 4 5 6 7
1 2 3 4 5 6 7


 


 

Output : 
 

1 2 3 4 5 6 7
 2 3 4 5 6 7
 3 4 5 6 7
 4 5 6 7
 5 6 7
 6 7 
 7
 6 7
 5 6 7
 4 5 6 7
 3 4 5 6 7
 2 3 4 5 6 7
1 2 3 4 5 6 7

Time Complexity : O(rows_no*rows_no) ,where rows_no is rows value taken from user.

Space Complexity : O(1) ,as we are not using any extra space.

Comment