![]() |
VOOZH | about |
For any given number n, print Hollow and solid Squares and Rhombus made with stars(*).
Examples:
Input : n = 4 Output : Solid Rhombus: **** **** **** **** Hollow Rhombus: **** * * * * ****
1. Solid Rhombus : Making Solid Rhombus is a bit similar to making solid square rather than the concept that for each ith row we have n-i blank spaces before stars as:
- - - ****
- - ****
- ****
****
2. Hollow Rhombus : Formation of Hollow Rhombus uses the idea behind formation of hollow square and solid rhombus. A hollow square with n-i blank spaces before stars in each ith rows result in formation of hollow rhombus.
Solid Rhombus: ***** ***** ***** ***** ***** Hollow Rhombus: ***** * * * * * * *****
Time Complexity: O(r2), where r represents the given number of rows.
Auxiliary Space: O(1), no extra space is required, so it is a constant.
solidRhombus function:
hollowRhombus function:
Solid Rhombus: ***** ***** ***** ***** ***** Hollow Rhombus: ***** * * * * * * *****
The time complexity of both functions is O(n^2), because there are two nested loops that iterate over all the rows and columns of the rhombus.
The space complexity is O(1), because only a constant amount of memory is used regardless of the size of the rhombus.