Page Numbering — Puzzle for Interview rounds

Question :

Pages of a book are numbered sequentially starting with 1. If the total number of decimal digits used is equal to 1578, how many pages are there in the book?

Solution :

The answer is 562 pages

Let D(n) be the total number of decimal digits in the first n positive integers (book pages). The first nine numbers are one-digit, therefore D(n) = n for 1 ≤ n ≤ 9.

The next 90 numbers from 10 to 99, inclusive, are two-digits. Hence,

D(n) = 9 + 2(n − 9) for 10 ≤ n ≤ 99.

The maximal value of D(n) for this range is D(99) = 189, which means that some three-digit numbers are needed to reach the total digit count of 1578 given in the puzzle. There are 900 three-digit decimals, which leads to the formula

D(n) = 189 + 3(n − 99) for 100 ≤ n ≤ 999.

To answer the puzzle’s question, we need to solve the equation

189 + 3(n − 99) = 1578.

Its solution is n = 562.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store