Back to Interview Prep

Warm Up · Star Pattern

Right-Angled Number Triangle

Problem Statement

Write a program that prints a right-angled triangle of numbers of height n.

Output

1
12
123
1234

Approach

  • Outer loop (Rows): Run a loop from i = 0 to i < n. Each iteration represents a new row.
  • Inner loop (Numbers): Run an inner loop from j = 0 to j <= i, and append j + 1 to the row.
  • Build and Print: Construct a string for the row and print it after the inner loop ends.

Time & Space Complexity

Time Complexity: O(n^2) - each row can have up to n numbers.

Space Complexity: O(n) - temporary string to build each row.

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