Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Page Numbering Math Problem
00:00
5 left

Page Numbering Math Problem

MediumPython

Problem

It takes 1000 digits to number the pages of a book consecutively. How many pages are there?

Implement count_pages(total_digits) to return the page count when numbering starts at 1. Return -1 when no whole page count uses exactly that many digits, and return 0 when total_digits is 0. The input is a nonnegative integer.

Constraints

  • 0 <= total_digits <= 10^18
  • Page numbering starts at 1
  • Pages are numbered consecutively without skipped numbers
  • Return -1 when the digit count ends partway through a page

Function Signature

def count_pages(total_digits):
Interviewer

Your question is Page Numbering Math Problem. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.