Data Structures & AlgorithmsModerateTCS NQT · counting
Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code.
Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code.
print(sum(1 for x in range(1000, 10000) if x % 11 == 0))What is printed?
- A. 818
- B. 819
- C. 909
- D. 90
Correct answer: B. 819
floor(9999 / 11) - floor(999 / 11) = 909 - 90 = 819. Counting from 1 to 9999 instead gives 909.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] have decimal digits summing to exactly 10? Run the code. python print(sum(1 for x in range(1, 101)…
- Problem: What is the minimum number of bit flips needed to make the binary string '00110' non-decreasing (all 0s then all 1s)? Run the…
- Problem: How many pairs (i < j) of 'aabab' have s[i] = 'a' and s[j] = 'b'? Run the code. python s = 'aabab' print(sum(1 for i in…
- Problem: How many distinct products a[i] a[j] (i < j) does [1, 2, 3, 4] produce? Run the code. python from itertools import combinations…
- Problem: What is the smallest positive integer missing from [3, 4, -1, 1]? Run the code. python a = [3, 4, -1, 1] m = 1 while m in a: m +=…
- Problem: What is the sum of the lengths of all contiguous subarrays of [1, 2, 3]? Run the code. python a = [1, 2, 3] print(sum(len(a[i:j])…