Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
Items of size 6, 5, 4, 3, 2 must be packed into bins of capacity 10 using first-fit decreasing. How many bins are used?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Sort decreasingly and put each item into the first bin with room. The total size 20 needs at least 2 bins, and first-fit achieves exactly that here.
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 substrings of "abcabc" are anagrams of "abc" (that is, have the same letters with the same counts)?
- What is the total number of 1-bits in the binary representations of all integers from 0 to 31 inclusive?
- How many integers from 1 to 100 inclusive are perfect squares or perfect cubes?
- What is the minimum number of single-character replacements needed to make "abcdba" a palindrome?
- How many well-formed strings of 3 pairs of parentheses (length 6) exist?
- On a line with cells 1 to 10, a lamp at position p lights cells p-2 to p+2. Lamps are placed at positions 1, 4, 6, 9. Do they light every…