Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: What is the sum of all two-digit numbers that are divisible by the sum of their digits? Run the code.
Problem: What is the sum of all two-digit numbers that are divisible by the sum of their digits? Run the code.
print(sum(x for x in range(10, 100) if x % sum(map(int, str(x))) == 0))What is printed?
- A. 23
- B. 1077
- C. 1122
- D. 45
Correct answer: B. 1077
23 two-digit numbers (10, 12, 18, 20, 21, 24, …, 90) are divisible by their digit sum and add up to 1077. 23 is the count, including 1..9 gives 1122, and 45 is just 1 + … + 9.
More Coding Interview Problems questions
- Problem: How many integers in [1, 1000] are both perfect squares and perfect cubes? Run the code. python print(sum(1 for x in range(1…
- Problem: How many integers in [1, 100] are divisible by neither 2 nor 3? Run the code. python print(sum(1 for x in range(1, 101) if x % 2…
- Problem: How many ordered pairs (a, b) with 1 <= a, b <= 9 make a b a perfect square? Run the code. python print(sum(1 for a in range(1…
- Problem: What is the time complexity of Johnson's all-pairs shortest path algorithm on a sparse graph with V vertices and E edges?
- Problem: Which problem asks for the minimum number of rectangles of size 1 x 2 needed to tile a board with some cells removed (domino…
- Problem: What does the Hall condition require for a bipartite graph to have a matching covering the left side?