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))
  1. A. -1 0 (-3, 2)
  2. B. -1 0 (-2, 1)
  3. C. 0 0 (-3, 2)
  4. 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

Exams that ask this topic