Data Structures & AlgorithmsHardLeetCode-style · TCS NQT
Flowers bloom on the days [1, 10, 3, 10, 2] (one flower per position). You need m = 3 bouquets, and each bouquet needs k = 1 adjacent bloomed flowers. What is the minimum day on which you can make 3 bouquets, or −1 if it is impossible?
- A. 4
- B. 3
- C. 10
- D. 5
Correct answer: B. 3
Binary search the day d: count how many disjoint runs of length k of flowers with bloom ≤ d you can take greedily, and check it reaches m. The feasibility test is monotone in d. Taking the day of the m-th earliest bloom is wrong when the flowers must be adjacent.
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
- 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…
- 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…