Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Boats carry at most 2 people and a weight limit of 10 per boat. Four people weigh 3, 5, 3 and 4. What is the minimum number of boats needed to carry everyone?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
Sort the weights and pair the heaviest remaining person with the lightest when the sum fits. Pairing the two heaviest first may waste capacity.
More Coding Interview Problems questions
- Problem: What is the smallest integer x with x·x ≥ 1,000,000,000?
- Problem: A grid holds oranges: 2 = rotten, 1 = fresh, 0 = empty: [[2,1,1],[1,1,0],[0,1,1]]. Each minute every fresh orange adjacent…
- Problem: Courses 0–5 have prerequisites: 1 needs 0, 2 needs 1, 3 needs 2, 4 needs 5, 5 needs 4. A course can be taken only after all its…
- Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7]…
- Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it…
- Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).