Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: In the expression print(2**3**2, (2**3)**2) what are the two values printed, in order?
- A. 64 512
- B. 512 64
- C. 512 512
- D. 8 64
Correct answer: B. 512 64
Exponentiation in Python is right-associative, so 2**3**2 means 2**(3**2) = 512. Evaluating left to right gives 64, the second printed value.
More Coding Interview Problems questions
- Problem: What does this print? x = [1, 2, 3] y = x y += [4] z = x[:] z.append(5) print(len(x), len(z))
- Problem: What is printed by this snippet? d = {} d['b'] = 1 d['a'] = 2 d['b'] = 3 print(list(d.items()))
- Problem: What is the output? print(sorted({3,1,2} & {2,3,4}), 3 in {1,2,3}, len({1,1,2}))
- Problem: The number 1000000007 is used as a modulus in competitive programming. How many times does the decimal digit 7 appear in the…
- Problem: In a bit-trick loop, n = 0b101101 is processed by repeatedly computing n &= n − 1 until n becomes 0. How many iterations are…
- Problem: The XOR of the values 1 through 10 is XOR-ed with the XOR of the values 1 through 9. What is the resulting value?