Data Structures & AlgorithmsModerateTCS NQT · counting
Problem: How many 2-digit numbers have both digits odd? Run the code.
Problem: How many 2-digit numbers have both digits odd? Run the code.
print(sum(1 for x in range(10, 100) if int(str(x)[0]) % 2 == 1 and int(str(x)[1]) % 2 == 1))What is printed?
- A. 20
- B. 16
- C. 30
- D. 25
Correct answer: D. 25
Each digit is one of 1, 3, 5, 7, 9, giving 5 * 5 = 25 numbers.
More Coding Interview Problems questions
- Problem: How many pairs (i < j) of [1, 3, 5, 7, 9] have a[i] + a[j] >= 10? Run the code. python a = [1, 3, 5, 7, 9] print(sum(1 for i in…
- Problem: What is the maximum sum of any 3 consecutive elements of [1, -2, 3, 4, -1]? Run the code. python a = [1, -2, 3, 4, -1]…
- Problem: How many integers in [1, 100] are perfect squares or perfect cubes? Run the code. python sq = {x x for x in range(1, 11)} cu = {x…
- Problem: What is the sum of the digits of 2^10 = 1024? Run the code. python print(sum(int(c) for c in str(2 10))) What is printed?
- Problem: What is the product of the distinct elements of [2, 2, 3, 4, 4]? Run the code. python a = [2, 2, 3, 4, 4] p = 1 for x in set(a)…
- Problem: What is the minimum absolute difference between two values of the sorted list [1, 5, 6, 9]? Run the code. python a = sorted([1…