Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(int('12', 8) + int('0x1f', 16))- A. 43
- B. 31
- C. 41
- D. 21
Correct answer: C. 41
'12' in base 8 is 10, and '0x1f' in base 16 is 31, so the sum is 41. The trap 21 mistakes the base-8 digits as decimal.
More Coding Interview Problems questions
- Problem: How many strings of length 4 over {a, b} contain neither 'aa' nor 'bb' as a substring? Run the code. python from itertools import…
- Problem: What is the sum of Euler's totient phi(k) for k = 1 to 20? Run the code. python from math import gcd print(sum(sum(1 for g in…
- Problem: How many integers in [1, 100] have exactly 4 positive divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1…
- Problem: What is the maximum number of pairwise non-overlapping non-empty subarrays of [1, -1, 2, -2, 3, -3] each having sum zero? Run the…
- Problem: How many 3-element subsets of {1, 2, 3, 4, 5, 6} have a sum divisible by 3? Run the code. python from itertools import…
- Problem: Minimum number of deletions so that no two adjacent characters of 'aaabbb' are equal. Run the code. python s = 'aaabbb' kept = []…