Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Solution: Nth Digit
We'll cover the following
Problem Statement
Examples
Solution
Step-by-step Algorithm
Algorithm Walkthrough
Initial Values
Step 1: Determine Digit Length
Step 2: Move to Two-Digit Numbers
Step 3: Move to Three-Digit Numbers
Step 4: Move to Four-Digit Numbers
Step 5: Move to Five-Digit Numbers
Step 6: Find the Exact Number and Digit
Code
Complexity Analysis

Problem Statement

Given a positive integer n, find the n<sup>th</sup> digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13... and so on.

Examples

  • Example 1:

    • Input: n = 3
    • Expected Output: 3
    • Justification: The third digit in the sequence 1, 2, 3, 4, 5, 6, 7... is 3.
  • Example 2:

    • Input: n = 110000
    • Expected Output: 2
    • Justification: In the sequence, the 110,000th digit is part of a larger number where the pattern has expanded beyond single, double, and triple digits

.....

.....

.....

Like the course? Get enrolled and start learning!