Skip to content

Instantly share code, notes, and snippets.

@suejungshin
Created October 31, 2019 16:11
Show Gist options
  • Save suejungshin/a240fef8fbbcf64f25907ad3b5521639 to your computer and use it in GitHub Desktop.
Save suejungshin/a240fef8fbbcf64f25907ad3b5521639 to your computer and use it in GitHub Desktop.
Suejung Shin Week 2 interview prompt
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) {
if (numRows === 0) {
return [];
}
if (numRows === 1) {
return [[1]];
}
let almostDoneArray = generate(numRows - 1);
let almostDoneArrayLastElement = almostDoneArray[almostDoneArray.length-1]
let lastResultElement = [];
lastResultElement.push(1)
for (let i = 0; i < almostDoneArrayLastElement.length - 1; i++) {
lastResultElement.push(almostDoneArrayLastElement[i] + almostDoneArrayLastElement[i+1])
}
lastResultElement.push(1);
almostDoneArray.push(lastResultElement);
return almostDoneArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment