Data Structures & AlgorithmsModerateTCS NQT · CAT · MBA placement
A truck carries at most 5 boxes. Box types are given as (number of boxes of this type, units per box): [(1, 3), (2, 2), (3, 1), (2, 4)]. What is the maximum number of units you can load?
- A. 9
- B. 14
- C. 16
- D. 15
Correct answer: D. 15
Load boxes in decreasing order of units per box, taking as many of each type as the remaining capacity allows. Taking types in the order listed leaves more valuable boxes behind.
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 contiguous subarrays of 2 3 4 1 6 9 have a product divisible by 6?
- How many contiguous subarrays of 5 2 7 1 8 3 6 4 have an ODD length and a sum divisible by 7?
- What is the sum, over all non-empty contiguous subarrays of 5 3 6 1 4, of their XOR values, taken modulo 1000?
- How many arrays of length 3 with entries in {0, 1, 2, 3} have a sum divisible by 4?
- How many ORDERED pairs (i, j) with i ≠ j in 1 4 6 9 10 3 5 satisfy that A[i] + A[j] is divisible by 5?
- How many contiguous subarrays of 1 3 5 2 4 6 1 have a sum that is a perfect square (0 is not present here)?