Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the number of integers in [1, 999] whose digit product is 0? Run the code.
Problem: What is the number of integers in [1, 999] whose digit product is 0? Run the code.
print(sum(1 for x in range(1, 1000) if '0' in str(x)))What is printed?
- A. 180
- B. 171
- C. 189
- D. 99
Correct answer: A. 180
Two-digit numbers with a zero: 9; three-digit: 900 − 729 = 171; total 180. Counting only three-digit numbers gives 171, counting zero digits instead of numbers gives 189, and checking only the last digit gives 99.
More Coding Interview Problems questions
- Problem: How many distinct pairs (i < j) of [6, 10, 15, 21] have gcd(ai, aj) = 1? Run the code. python from math import gcd a = [6, 10…
- Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code. python from math import lcm…
- Problem: Which technique gives the number of distinct subarrays of an array of length n in O(n log n) time using a suffix structure?
- Problem: Which statement about the Knuth optimization for interval DP is correct when its monotonicity conditions hold?
- Problem: What is the time complexity of building a suffix array with prefix doubling and radix sort?
- Problem: Which problem is solved by the Aho-Corasick automaton?