Back to Interview Prep

Warm Up · Star Pattern

Right-Angled Triangle of Repeated Numbers

Problem Statement

Write a program that prints a right-angled triangle where each row contains the same number repeated.

Output

1
22
333
4444

Approach

  • Outer loop (Rows): Loop from i = 0 to i < n.
  • Inner loop (Numbers): Loop from j = 0 to j <= i, appending i + 1 as a string.
  • Build and Print: Build the row string and print it.

Time & Space Complexity

Time Complexity: O(n^2)

Space Complexity: O(n) for the temporary row string.

Explanation

  • The only change from the Right-Angled Number Triangle is appending i + 1 (the row number) instead of j + 1 (the column number).

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