Data Structures & AlgorithmsModerateGATE CS · TCS NQT
What is the smallest non-negative integer x for which x³ + x is at least 1000?
- A. 9
- B. 10
- C. 32
- D. 500
Correct answer: B. 10
x³ + x is strictly increasing, so binary search finds the first x with the predicate true: 9³ + 9 = 738 fails and 10³ + 10 = 1010 passes. Reading the expression as x² + x gives 32, as x + x gives 500, and 9 is the last failing value.
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
- 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?
- A train makes three legs of lengths 1, 3 and 2 km. Each leg except the last must be finished in whole hours (a partial hour is rounded…
- How many indices i in [1, 7, 3, 6, 5, 6] have the sum of elements strictly left of i equal to the sum of elements strictly right of i?
- How many contiguous subarrays of [1, -1, 2, -2, 3, -3, 1] sum to exactly 1?