Data Structures & AlgorithmsVery hardICPC regional · GATE CS
Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins needed?
- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: B. 2
Bin packing is NP-hard in general, so the exact answer comes from search over assignments (here six items). First-fit, which places each item in the first bin with room, is a heuristic that can use an extra bin.
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
- How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?
- What is the maximum sum of a contiguous subarray of [4, -1, 2, 2, 5, -3, 4, 1] that contains at most 2 distinct values?
- What is the minimum number of characters you must delete from "abbabaab" (keeping the order of the rest) so that the result contains NO…
- How many ordered pairs (i, j) with i ≠ j exist in [2, 4, 3, 8, 6, 9] such that a[j] is divisible by a[i]?
- From the stick lengths [4, 2, 7, 5, 3, 6, 9], choose three different sticks that can form a non-degenerate triangle (the sum of any two…