Data Structures & AlgorithmsVery hardICPC regional · TCS NQT
Items as (weight, value) are [(4, 6), (2, 3), (5, 9), (3, 4), (6, 10), (1, 1)]. You must take EXACTLY 3 different items with total weight at most 10. What is the maximum total value?
- A. 16
- B. 19
- C. 15
- D. 25
Correct answer: A. 16
Knapsack with a count dimension: {(4,6), (5,9), (1,1)} weighs exactly 10 and is worth 16, which no other legal triple beats. Taking the top three values ignoring weight gives 25, the two most valuable items (19) already weigh 11, and reading the limit as < 10 gives 15.
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
- In one operation you may choose a contiguous subarray and increase every element in it by 1. Starting from [0, 0, 0, 0], what is the…
- How many contiguous subarrays of [1, 2, 1, 3, 3, 2, 4, 1] contain EXACTLY 2 distinct values?
- Evaluate 3 + 5 2 - 8 / 4 using standard precedence and integer division. What is the result?
- The exponent operator ^ is right-associative. What is the value of 2 ^ 3 ^ 2?
- How many valid (balanced) bracket sequences of length 8 are there using one type of bracket?
- A grid has the rows ..#.., .##.., ....., #.#.# (where '.' is open and '#' is a wall; all rows have length 5). Starting from the top-left…