Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Weights [2, 3, 3, 4, 1, 2] are packed into boxes of capacity 5 by first-fit decreasing. How many boxes are used?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
The total weight is 15, so at least 3 boxes are needed, and first-fit decreasing achieves 3 here by pairing 4 with 1 and 3 with 2, and 3 with 2.
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
- For an array of length 5 indexed 0 to 4, how many contiguous subarrays contain index 2?
- Among integers from 1 to 40 inclusive, which value has the largest number of 1-bits in binary? Report the smallest such value.
- How many index pairs i < j of [1, 2, 3, 4, 6, 6] satisfy a[i] a[j] = a[i] + a[j]?
- How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?
- Closed meeting intervals [1,3], [3,4], [2,5], [6,7] cannot share a room if they overlap even at one point. What is the minimum number of…
- How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?