Warm Up · Star Pattern
Reverse Right-Angled Triangle of Increasing Numbers
Problem Statement
Write a program that prints a reverse right-angled triangle where each row starts from 1 and the number of elements decreases with each row.
Output
1234 123 12 1
Approach
- Outer loop (Rows): Loop
ifrom0ton - 1. Each iteration represents a row. - Inner loop (Print Numbers): For each row, loop
jfrom0ton - i - 1and appendj + 1to a row string. - Print Row: After the inner loop, print the row string.
Time & Space Complexity
Time Complexity: O(n^2)
Space Complexity: O(n) for the temporary row string.
Your solution
Solve it in JavaScript and print the answer with console.log(). Run to see your output, then Submit to check it against the test cases.
// Write your solution in JavaScript // Print the answer with console.log()
Console
No output yet. Use console.log() to print values here.
Write your own solution and press Submit once to unlock the answer.