Data Structures & AlgorithmsHard
Five people weigh 3 5 3 4 2. Each boat holds at most two people and its total weight must not exceed 7. What is the minimum number of boats needed to carry everyone?
- A. 3
- B. 5
- C. 4
- D. 2
Correct answer: A. 3
Sort the weights and pair the heaviest person with the lightest one that fits, a two-pointer greedy that is optimal for at most two per boat. Sending one person per boat ignores pairing, and the sum-divided bound ignores the weight limit per boat.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the smallest positive integer k such that the residues of 3 5 8 12 14 modulo k (that is, each A[i] mod k) are all DISTINCT?
- How many index triples i < j < k in "abcdeacace" spell the subsequence 'ace' (characters need not be adjacent)?
- How many index triples i < j < k in "abacaba" give a palindromic subsequence S[i]S[j]S[k] of length 3 (that is, S[i] = S[k])?
- How many contiguous subarrays of 2 1 4 3 6 5 8 7 of length at least 2 contain EQUAL numbers of even and odd values?
- What is the length of the longest contiguous subarray of 3 6 9 4 12 18 5 in which EVERY element is divisible by the FIRST element of that…
- What is the maximum sum of a contiguous subarray of 3 1 3 2 4 1 5 whose elements are all DISTINCT?