Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(max([], default=-1), sum([]), divmod(-7, 3))
- A. -1 0 (-3, 2)
- B. -1 0 (-2, 1)
- C. 0 0 (-3, 2)
- D. -1 0 (-4, 2)
Correct answer: A. -1 0 (-3, 2)
max with a default returns -1 for an empty list, sum of nothing is 0, and divmod floors the quotient to -3 with remainder 2 since -3 * 3 + 2 = -7.
More Coding Interview Problems questions
- Problem: What does the following print? python print(2 -1, 7 % -3)
- Problem: What does the following print? python print(sorted([3, 1, 2], key=lambda x: -x)[0]) What is printed?
- Problem: Starting from 3, you may apply two operations: "+1" or "×2". What is the minimum number of operations needed to reach exactly 50?
- Problem: A knight starts at square (0,0) on an infinite chessboard. What is the minimum number of knight moves needed to reach square (4,5)?
- Problem: The complete graph K6 has 15 edges. A perfect matching of 3 disjoint edges is removed. How many edges remain?
- Problem: What is the chromatic number of the cycle graph C5 (5 vertices in a single cycle)? The chromatic number is the least number of…