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 = 0toi < n. - Inner loop (Numbers): Loop from
j = 0toj <= i, appendingi + 1as 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 ofj + 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.