Back to Interview Prep

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 i from 0 to n - 1. Each iteration represents a row.
  • Inner loop (Print Numbers): For each row, loop j from 0 to n - i - 1 and append j + 1 to 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.

You're viewing a free lesson. Sign up free to track your progress and unlock the full course.Sign up freeSign in