Data Structures & AlgorithmsVery hardICPC regional · CAT · MBA placement
Problem: The 10 numbers 1 to 10 are split into two groups of five. The sum of the group containing 10 is S. How many different values of S are possible?
- A. 21
- B. 126
- C. 26
- D. 20
Correct answer: A. 21
S = 10 + (sum of four of 1..9), which takes every value from 20 to 40: 21 values. 126 counts the splits, ignoring the 10 constraint gives 26, and 40 − 20 without + 1 gives 20.
More Coding Interview Problems questions
- Problem: In a directed acyclic graph with arcs 0→1, 0→2, 1→3, 2→3, 3→4, 2→4, how many distinct topological orders exist?
- Problem: Compute the number of trailing zeros of 25! in base 5 (that is, how many times 5 divides 25!).
- Problem: A stack starts with the characters pushed in the order a, b, c, d. The following pops occur: pop, pop, then push e, pop. Which…
- Problem: The grid 2×3 contains the values [[1,2,3],[4,5,6]]. From the top-left cell you move right or down to the bottom-right, collecting…
- Problem: The sum of the digits of 2^15 is what value?
- Problem: How many subarrays of [2, 4, 1, 3, 6, 5] have an even sum? Run the code. python a = [2, 4, 1, 3, 6, 5] print(sum(1 for i in…