Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(sorted(['b', 'B', 'a', 'A']))
- A. ['a', 'A', 'b', 'B']
- B. ['A', 'B', 'a', 'b']
- C. ['b', 'B', 'a', 'A']
- D. ['B', 'A', 'b', 'a']
Correct answer: B. ['A', 'B', 'a', 'b']
Uppercase letters have smaller code points than lowercase, so all capitals come first in code-point order.
More Coding Interview Problems questions
- Problem: Selection sort is run on [4, 3, 2, 1] in the usual way (for each position, find the minimum of the unsorted suffix and swap it…
- Problem: A Rule 90 cellular automaton on an infinite line starts with a single live cell. A cell's next state is 1 exactly when its two…
- Problem: A lucky 4-digit ticket has the sum of its first two digits equal to the sum of its last two digits. Each ticket number runs from…
- Problem: A grid of 5×5 cells has 'X' blocked cells at (0,2), (1,2), (2,2), (3,2) (row, column, 0-indexed); the rest are open. Cells…
- Problem: On a grid, a diagonal step costs 2 and a straight step costs 1 (moves are up, down, left, right, and the four diagonals). What is…
- Problem: The cycle graph C8 has vertices 0–7 with i adjacent to (i+1) mod 8. How many unordered pairs of vertices are at distance exactly…