Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
Wood sticks have lengths [232, 124, 456] (integers). You need K = 7 pieces of EQUAL integer length, and you may cut each stick into as many pieces as you like (leftover parts are discarded). What is the largest integer length you can obtain?
- A. 116
- B. 91
- C. 114
- D. 65
Correct answer: C. 114
Binary search L with the test Σ floor(w / L) ≥ 7: at 114 the counts are 2 + 1 + 4 = 7, at 115 only 6. The average 812 / 7 = 116 ignores the wasted leftovers, testing > 7 instead of ≥ 7 gives 91, and 456 / 7 = 65 uses only the longest stick.
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 unordered pairs of positions (i < j) in [9, 1, 6, 14, 3, 11, 7] have an absolute difference of at most 4?
- For the multiset [1, 6, 1, 9, 4, 12, 3], consider all unordered pairs of distinct positions and their absolute differences. What is the…
- What is the smallest non-negative integer x for which x³ + x is at least 1000?
- A binary search for the FIRST index where a predicate becomes true uses: lo = 0, hi = n, while lo < hi: mid = (lo + hi) // 2; if…
- Parcels with weights [4, 9, 2, 7, 5, 8, 3, 6] must be shipped in this order, and a ship carries a contiguous block each day. What is the…
- What is the largest integer k such that 1 + 2 + ... + k is at most 2023?