Data Structures & AlgorithmsModerateCodeforces Div2 D · GATE CS
Assertion (A): Binary search on the answer requires that the feasibility predicate is monotone. Reason (R): Only a monotone predicate lets us discard half of the answer range after each test.
- A. Both A and R are true, but R is not the correct explanation of A
- B. Both A and R are true, and R is the correct explanation of A
- C. A is true, but R is false
- D. A is false, but R is true
Correct answer: B. Both A and R are true, and R is the correct explanation of A
If feasibility is true for some value, every larger (or smaller) value is true too, so each test rules out a whole half of the range. Without monotonicity the halving step is unsafe.
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
- Assertion (A): The greedy 'largest coin first' is optimal for the coin set {1, 3, 4} when the amount is 6. Reason (R): A coin system whose…
- Which of the following statements about the sliding window technique on arrays with NEGATIVE numbers is/are correct? I. A plain…
- The array [7, 2, 5, 10, 8, 3, 6] must be split into exactly 3 contiguous non-empty parts (order kept). What is the smallest possible value…
- An array has 10^5 values and you need the k-th smallest value among all pair sums a[i] + a[j] with i < j. Which approach is the right fit?
- From [4, 9, 2, 7, 5, 1] you may pick any elements (each at most once). What is the minimum number of picks so that the picked sum is at…
- How many index triples i < j < k in [-2, -1, 0, 1, 2, 3] have a sum of exactly 0?