Company: American_Express_SDE_Profile_11nov

Difficulty: medium

Problem Statement

Count Digit One Problem Description Write a function: int solution(int N); that, given an integer N, reports how many times the digit 1 shows up across the decimal representations of every positive integer from 1 up to and including N. Examples Example 1: Input: N = 13 Output: 6 Explanation: Here's why: the positive integers up to 13 are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 and 13; the digit 1 shows up six times in total: once in 1, once in 10, twice in 11, once in 12, and once in 13. Constraints Write an efficient algorithm for the following assumptions: N is an integer within the range [0..100,000,000].

More American_Express_SDE_Profile_11nov OA questionsInterview experiences