R

E

A

C

T

O

xamples 

epeat

ode

pproach

ptimize

est

{Pascal's Triangle}

Problem

Given a value, n, construct a flat array of the values in Pascal's Triangle to that depth.

The approach

1. Start with an empty array to hold your values.

 

2. Iterate n times (the depth of the triangle)

 

3. In a nested for-loop, iterate i + 1 times (each row has i + 1 elements)

 

4. Insert a 1 if you are at an edge, otherwise calculate an interior value

One Solution

Another Solution

Extra Credit: 

If your interviewee solves the answer quickly, have them design an algorithm that will print the triangle like this

Conclusion  

Solution : https://repl.it/BhFY/1

Solution (Binomial): https://repl.it/BhIQ

Pascal's Triangle

By ryankdwyer

Pascal's Triangle

Technical interview problem on generating string permutations

  • 991