Problem Link - Print Pattern in Recursion
Problem Statement:
Given an integer N, we need to print an upside-down triangle of stars where the base of the triangle has N stars and each subsequent row contains one less star than the row above it.
Approach:
- Loop through Rows:
- Use a loop that starts from N and decrements down to 1.
- For each iteration, print the corresponding number of stars.
- Print Stars:
- In each iteration, print a row of stars based on the current row number.
Complexity:
- Time Complexity: O(N^2) . The total number of stars printed is N*(N+1)/2, which results in O(N^2) total time due to the nested printing in each recursive call.
- Space Complexity: O(N) due to the recursion stack. Each recursive call adds a new frame to the stack until the base case is reached.