Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 10000] have decimal digits summing to 12? Run the code.
Problem: How many integers in [1, 10000] have decimal digits summing to 12? Run the code.
print(sum(1 for x in range(1, 10001) if sum(map(int, str(x))) == 12))What is printed?
- A. 415
- B. 416
- C. 414
- D. 420
Correct answer: A. 415
A digit-by-digit count (each digit 0 to 9, length up to 4) gives 415 integers in [1, 10000] whose digit sum is 12.
More Coding Interview Problems questions
- Problem: What is the length of the longest palindromic subsequence of 'character'? Run the DP. python def lps(s): n = len(s) dp = [[0] n…
- Problem: What is the minimum number of characters to insert to make 'leetcode' a palindrome? Use length minus longest palindromic…
- Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code. python import itertools print(sum(1 for t in…
- Problem: How many derangements (permutations with no fixed point) of 1..6 exist? Run the code. python from itertools import permutations…
- Problem: How many permutations of 0..4 have exactly one inversion? Run the code. python from itertools import permutations print(sum(1 for…
- Problem: What is the smallest positive integer with exactly 10 positive divisors? Run the search. python n = 1 while sum(1 for d in…