Get the results as 120 using five zeros
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This puzzle looks impossible at first because five zeros seem to give you nothing but zero. The trick is to stop treating 0 as a dead end and start using operations whose value at zero is meaningful. The cleanest solution uses factorial, because 0! = 1, and five ones can be turned into 5! = 120.
The Shortest Elegant Solution
A valid expression is:
- '
(0! + 0! + 0! + 0! + 0!)!'
Why it works:
- each
0!equals1 - the sum becomes
1 + 1 + 1 + 1 + 1 = 5 - '
5! = 120'
That uses exactly five zeros and produces the target.
Verify It Programmatically
This prints 120.
The interesting part of the puzzle is not the arithmetic. It is recognizing which operations make zero useful.
Why Factorial Changes the Game
Most ordinary operations keep zero trapped:
- '
0 + 0 = 0' - '
0 - 0 = 0' - '
0 * 0 = 0'
Division is not much help either because 0 / 0 is undefined.
Factorial is different because 0! is defined as 1. That gives you a way to convert each zero into something positive. Once you have several ones, many more constructions become possible.
For the target 120, the number 5 is especially useful because 5! = 120.
Puzzle-Solving Strategy
A general strategy for puzzles like this is:
- identify operations that turn the given symbol into a nontrivial value
- look for a target number with a simple decomposition
- use the limited digits as building blocks for that decomposition
In this puzzle:
- the special operation is factorial
- the target
120is5! - five zeros can be turned into five ones through
0!
That is why the solution feels neat rather than forced.
Are Other Solutions Possible?
Yes, depending on the allowed operations. If concatenation, decimal points, gamma functions, or more exotic notation are permitted, you can invent many alternatives. But in most puzzle settings, the point is to find the simplest expression under standard arithmetic plus factorial.
That simplicity matters. A puzzle solution is stronger when it uses a small number of conventional operations and makes the structure obvious.
A Related Example
Once you understand the idea, similar puzzles become easier. For example, if someone asks for 24 using four zeros, the same pattern works:
- '
(0! + 0! + 0! + 0!)!'
That becomes 4! = 24.
The structure is identical. Convert zeros to ones, count how many you have, then factorial the sum.
Why 0! = 1
Some people feel the puzzle is "cheating" because factorial of zero seems unintuitive. It is not a trick definition. 0! = 1 is a standard mathematical convention that makes combinatorics and recurrence relations work cleanly.
For example, the factorial recurrence n! = n * (n - 1)! gives:
- '
1! = 1 * 0!'
Since 1! = 1, that forces 0! = 1.
That is why the puzzle is mathematically legitimate rather than a loophole.
Common Pitfalls
The biggest mistake is assuming only basic arithmetic is allowed and giving up because all simple combinations of zeros stay at zero.
Another mistake is using more than five zeros accidentally by writing extra helper values or hidden constants.
A third issue is producing a huge expression when a much cleaner factorial-based construction already exists.
Summary
- The elegant solution is
(0! + 0! + 0! + 0! + 0!)! - Each
0!equals1, so the inside sum becomes5 - '
5!equals120' - The puzzle works because factorial gives zero a useful value
- The general lesson is to look for operations that change the role of the given symbols instead of combining them only with basic arithmetic
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.