Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code.
Problem: How many distinct values does floor(100 / i) take for i = 1 to 100? Run the code.
print(len({100 // i for i in range(1, 101)}))What is printed?- A. 20
- B. 10
- C. 19
- D. 100
Correct answer: C. 19
Values of 100 // i for i ≤ 10 are 10 distinct numbers, and for i > 10 the quotient takes the 9 values 1..9, total 19. The 2√n estimate gives 20, stopping at i = 10 gives 10, and real division gives 100.
More Coding Interview Problems questions
- Problem: What is the number of ways to write 20 as an ordered sum of the parts 1 and 2 (compositions)? Run the DP. python f = [1, 1] for i…
- Problem: How many 4-digit numbers have all digits equal to or greater than the digit before them (non-decreasing)? Run the code. python…
- Problem: What is the maximum value of a[i] XOR a[j] over i < j for a = [3, 10, 5, 25, 2, 8, 17]? Run the code. python a = [3, 10, 5, 25…
- Problem: How many subarrays of [1, -1, 1, -1, 1] have sum 0? Run the prefix-count code. python from collections import Counter a = [1, -1…
- Problem: What is the number of paths from (0,0) to (4,4) using right and up moves that never touch the diagonal cells (i, i) except at the…
- Problem: What is the number of integers in [1, 10000] that are perfect squares and also end in the digit 9? Run the code. python…