Re:Amazon’s Interview Questions And Why I Don’t Work At Amazon
by andrewcooke on Sunday October 20, 2013 @09:08PM
(#6582500)
no spaces.
but you can get the formula by imagining the numbers as piles of pennies and then completing them to make a square and then splitting down the diagonal
*
**
***
*..
**.
***
\.. \
*\. + \
**\ \
where a \ is half a penny. so * = \\
so it's 1/2 * n * n (ie half the square) plus an extra 1/2 for each one on the diagonal.
but you can get the formula by imagining the numbers as piles of pennies and then completing them to make a square and then splitting down the diagonal
where a \ is half a penny. so * = \\so it's 1/2 * n * n (ie half the square) plus an extra 1/2 for each one on the diagonal.
so it's n * n/2 + n/2 = (n+1) * n/2