Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(sorted([3, 1, 2], key=lambda x: -x)[0])What is printed?
- A. 3
- B. 1
- C. 2
- D. -5
Correct answer: A. 3
Sorting by the negated key puts the largest value first, so element 0 is 3.
More Coding Interview Problems questions
- 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…
- Problem: What is the independence number of the cycle graph C7 (the maximum number of vertices with no two adjacent in the 7-cycle)?
- Problem: The binary search tree is built by inserting 8, 3, 10, 1, 6, 14, 4, 7, 13 in this order. How many nodes lie at the maximum depth…