Number Staircase
JavaScript
Easy
3 views
Problem Description
Given n, print staircase pattern of numbers. Line i has numbers from 1 to i (space separated).
Input Format
One integer n.
Output Format
n lines pattern.
Sample Test Case
Output:
1
1 2
1 2 3
1 2 3 4
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const n=Number(s);let out=[];for(let i=1;i<=n;i++){let row=[];for(let j=1;j<=i;j++)row.push(String(j));out.push(row.join(' '));}process.stdout.write(out.join('\
'));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!