The cannonballs that make a square and a pyramid
Cannonballs are stacked in a square pyramid: one ball on top, a 2 by 2 layer beneath it, then 3 by 3, and so on down to an n by n base. A sergeant notices that the same balls, laid out flat, would form a perfect square.
- How many cannonballs are there? (More than one, that is; a single ball trivially works.)
- Write down the formula for the number of balls in a pyramid with n layers and show how you would search.
Show a hint
The pyramid with n layers holds 1 + 4 + 9 + ... + n squared = n(n + 1)(2n + 1)/6 balls. Try n up to about 30.
Your answer
Solving needs a free account
Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.
Discussion
Sign in to join the discussion · reading is open to everyone
💡 Discussion rules
- No full solutions here. Hints and approaches only.
- Complexity, edge cases and intuition are the point.
- Interview experiences are welcome. Respect your NDAs.
Loading discussion…
Learn the concepts
The theory behind this question.
Related questions
The person whose age is the square root of the yearA hundred animals for a hundred poundsThe four-digit number that reverses when multiplied by fourThe taxicab numberThe two-digit number that is the square of its digit sum
All questions →