Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Staircase problem implemented in JavaScript
// Time Complexity O(n2)
const staircase = (n, c) => {
let y = [];
let s;
for (let i = 1; i <= n; i++) y[i - 1] = i;
for (let j = 1; j <= n; j++) {
s = y.length - j;
console.log(' '.repeat(s), c.repeat(j));
}
}
staircase(6, '#');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment