Data Structures & AlgorithmsHardProduct company OA
The sorted array [3, 4, 7, 10, 11] contains some positive integers. What is the 4th positive integer MISSING from it?
- A. 6
- B. 5
- C. 8
- D. 9
Correct answer: A. 6
Missing positives in order: 1, 2, 5, 6, 8, 9, … → the 4th is 6. In O(log n): before a[i] there are a[i] − (i + 1) missing numbers (2, 2, 4, 6, 6), so the answer lies between 4 and 7: 4 + (4 − 2) = 6. '8' counts missing numbers after 7 only.
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
- For [2, 3, 0, 4], out[i] is the product of all elements except a[i], computed with prefix and suffix products (no division). What is out?
- The intervals [1, 4], [6, 8], [2, 3], [8, 10], [12, 13] are sorted by start and merged (intervals that touch at an endpoint also merge)…
- A 'leader' is an element strictly greater than every element to its right (the last element is always a leader). Scanning from the right…
- The words stop, pots, opts, post, tops, spot, pot, top are grouped so that anagrams share a group (key = the sorted letters). How many…
- A stack is built from two queues with a costly push: enqueue x into the empty queue Q2, move every element of Q1 into Q2 one by one, then…
- With at most k = 2 character replacements, what is the length of the longest substring of 'AABCABBB' that can be turned into a single…