This is a classic interview question that was once asked at Amazon.
Let S be the set of all 5 digit numbers formed by the digits 1, 2, 3, 4, 5 without repetition. What is the sum of all numbers in S?
As usual, watch the video for a solution.
Can you solve this interview question?
Or keep reading.
.
.
“All will be well if you use your mind for your decisions, and mind only your decisions.” Since 2007, I have devoted my life to sharing the joy of game theory and mathematics. MindYourDecisions now has over 1,000 free articles with no ads thanks to community support! Help out and get early access to posts with a pledge on Patreon.
.
.
.
.
.
.
M
I
N
D
.
Y
O
U
R
.
D
E
C
I
S
I
O
N
S
.
P
U
Z
Z
L
E
.
.
.
.
Answer To Sum Of All Numbers Without Repetition
(Pretty much all posts are transcribed quickly after I make the videos for them–please let me know if there are any typos/errors and I will correct them, thanks).
We can do a smart calculation to avoid enumerating all numbers and tediously summing them.
We can sum all instances of each digit and them sum across all digits. Start with the digit 5 in the ten-thousands place.
5 _ _ _ _
The remaining 4 slots will contain the remaining 4 digits, which can be arranged in 4! ways. Thus there are 4! numbers that contain 5(104), and so the sum of all instances of the digit 5 in these numbers will be 5(104)4!.
But we could similarly put the digit 5 in the thousands place.
_ 5 _ _ _
By similar logic, there will be 4! numbers of this form, contributing 5(103)4! to the sum of all numbers. There are 3 more cases to consider.
_ _ 5 _ _
_ _ _ 5 _
_ _ _ _ 5
These cases will contribute 5(102)4!, 5(101)4!, and 5(100)4! to the sum. The total of these values is then:
5(104)4! + 5(103)4! + 5(102)4! + 5(101)4! + 5(103)4!
= 5(104 + 103 + 102 + 101 + 100)4!
We can do a similar calculation for the sums involving the digits 4, 3, 2, and 1.
4(104 + 103 + 102 + 101 + 100)4!
3(104 + 103 + 102 + 101 + 100)4!
2(104 + 103 + 102 + 101 + 100)4!
1(104 + 103 + 102 + 101 + 100)4!
Now we sum all of these sums. The factor (104 + 103 + 102 + 101 + 100)4! can be factored from these to get:
(5 + 4 + 3 + 2 + 1)(104 + 103 + 102 + 101 + 100)4!
= 15(1111)24
= 3,999,960
References
CareerCup
Amazon Interview Question for SDE1s
https://www.careercup.com/question?id=20347666
Toppr
https://www.toppr.com/ask/question/the-sum-of-all-five-digit-numbers-that-can-be-formed-using-the-digits-1234/
Published by
PRESH TALWALKAR
I run the MindYourDecisions channel on YouTube, which has over 1 million subscribers and 200 million views. I am also the author of The Joy of Game Theory: An Introduction to Strategic Thinking, and several other books which are available on Amazon.
(As you might expect, the links for my books go to their listings on Amazon. As an Amazon Associate I earn from qualifying purchases. This does not affect the price you pay.)
By way of history, I started the Mind Your Decisions blog back in 2007 to share a bit of math, personal finance, personal thoughts, and game theory. It’s been quite a journey! I thank everyone that has shared my work, and I am very grateful for coverage in the press, including the Shorty Awards, The Telegraph, Freakonomics, and many other popular outlets.
I studied Economics and Mathematics at Stanford University.
People often ask how I make the videos. Like many YouTubers I use popular software to prepare my videos. You can search for animation software tutorials on YouTube to learn how to make videos. Be prepared–animation is time consuming and software can be expensive!
Feel free to send me an email [email protected]. I get so many emails that I may not reply, but I save all suggestions for puzzles/video topics.
MY BOOKS
If you purchase through these links, I may be compensated for purchases made on Amazon. As an Amazon Associate I earn from qualifying purchases. This does not affect the price you pay.
Book ratings are from January 2023.
(US and worldwide links)
https://mindyourdecisions.com/blog/my-books

Mind Your Decisions is a compilation of 5 books:
(1) The Joy of Game Theory: An Introduction to Strategic Thinking
(2) 40 Paradoxes in Logic, Probability, and Game Theory
(3) The Irrationality Illusion: How To Make Smart Decisions And Overcome Bias
(4) The Best Mental Math Tricks
(5) Multiply Numbers By Drawing Lines

The Joy of Game Theory shows how you can use math to out-think your competition. (rated 4.3/5 stars on 290 reviews)

40 Paradoxes in Logic, Probability, and Game Theory contains thought-provoking and counter-intuitive results. (rated 4.2/5 stars on 54 reviews)

The Irrationality Illusion: How To Make Smart Decisions And Overcome Bias is a handbook that explains the many ways we are biased about decision-making and offers techniques to make smart decisions. (rated 4.1/5 stars on 33 reviews)

The Best Mental Math Tricks teaches how you can look like a math genius by solving problems in your head (rated 4.3/5 stars on 116 reviews)

Multiply Numbers By Drawing Lines This book is a reference guide for my video that has over 1 million views on a geometric method to multiply numbers. (rated 4.4/5 stars on 37 reviews)

Mind Your Puzzles is a collection of the three “Math Puzzles” books, volumes 1, 2, and 3. The puzzles topics include the mathematical subjects including geometry, probability, logic, and game theory.
Math Puzzles Volume 1 features classic brain teasers and riddles with complete solutions for problems in counting, geometry, probability, and game theory. Volume 1 is rated 4.4/5 stars on 112 reviews.
Math Puzzles Volume 2 is a sequel book with more great problems. (rated 4.2/5 stars on 33 reviews)
Math Puzzles Volume 3 is the third in the series. (rated 4.2/5 stars on 29 reviews)
KINDLE UNLIMITED
Teachers and students around the world often email me about the books. Since education can have such a huge impact, I try to make the ebooks available as widely as possible at as low a price as possible.
Currently you can read most of my ebooks through Amazon’s “Kindle Unlimited” program. Included in the subscription you will get access to millions of ebooks. You don’t need a Kindle device: you can install the Kindle app on any smartphone/tablet/computer/etc. I have compiled links to programs in some countries below. Please check your local Amazon website for availability and program terms.
US, list of my books (US)
UK, list of my books (UK)
Canada, book results (CA)
Germany, list of my books (DE)
France, list of my books (FR)
India, list of my books (IN)
Australia, book results (AU)
Italy, list of my books (IT)
Spain, list of my books (ES)
Japan, list of my books (JP)
Brazil, book results (BR)
Mexico, book results (MX)
MERCHANDISE
Grab a mug, tshirt, and more at the official site for merchandise: Mind Your Decisions at Teespring.