Data Structures & AlgorithmsHardTCS NQT Digital · counting
Problem: How many integers in [1, 1000] contain the digit 0? Run the code.
Problem: How many integers in [1, 1000] contain the digit 0? Run the code.
print(sum(1 for x in range(1, 1001) if '0' in str(x)))What is printed?
- A. 181
- B. 189
- C. 171
- D. 190
Correct answer: A. 181
Nine two-digit numbers (10 to 90) and 171 three-digit numbers contain a 0, and 1000 adds one more, for 181.
More Coding Interview Problems questions
- Problem: What is the minimum number of perfect squares (1, 4, 9, ...) that sum to 12? Run the DP. python INF = 10 9 dp = [0] + [INF] 12…
- Problem: How many non-decreasing strings of length 3 over the digits {0, 1, 2} exist? Run the code. python from itertools import product…
- Problem: What is the maximum sum of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5]? Run the DP. python a = [1, 101, 2, 3…
- Problem: How many unordered pairs of indices (i < j) of [5, 5, 5, 5] have a sum of 10? Run the code. python a = [5, 5, 5, 5] print(sum(1…
- Problem: What does the following print? python print(list(map(lambda x: x 2, filter(lambda x: x % 2, range(6))))) What is printed?
- Problem: What does the following print? python print(bool([]), bool([0]), bool(0.0), bool('False')) What is printed?