Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT
The sorted array [2, 3, 4, 7, 11] contains some positive integers. What is the 5th positive integer that does NOT appear in this array?
- A. 9
- B. 10
- C. 5
- D. 1
Correct answer: A. 9
Missing numbers are 1, 5, 6, 8, 9, ..., so the 5th is 9; binary search on a[mid] − (mid + 1) finds the spot. Adding k to the array length (5 + 5) gives 10, 5 is k itself, and 1 is only the first missing number.
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
- In how many ways can you choose 3 indices from the 9 positions 1 to 9 so that no two chosen positions are adjacent (consecutive integers)?
- What is the length of the longest contiguous subarray of [4, 7, 5, 6, 8, 9, 7, 6, 3, 4] in which the largest value minus the smallest…
- How many contiguous subarrays of [3, 1, 3, 2, 3, 1] have their maximum value occurring EXACTLY twice inside the subarray?
- How many strings of length 5 over the alphabet {a, b, c} contain no two adjacent equal letters when the letter is a or b (two adjacent c's…
- How many binary strings of length 6 have exactly 4 maximal runs (blocks of equal consecutive digits)?
- How many unordered pairs of different positions in [3, 8, 2, 9, 5, 4] have a product at most 24?