Data Structures & AlgorithmsModerateTCS CodeVita · Codeforces Div 2
What is the smallest positive integer missing from the array [3, 4, −1, 1]?
- A. 1
- B. 5
- C. 2
- D. 0
Correct answer: C. 2
1 is present, so 2 is the first gap. Cyclic sort places each value v at index v − 1 in O(n) time with O(1) extra space, and the answer is the first index holding the wrong 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
- What is the worst-case time complexity of finding the minimum in a rotated sorted array that may contain duplicates, using a binary search…
- For binary search over 1000 distinct sorted values with mid = (lo + hi) / 2 and the loop running while lo ≤ hi, what is the largest number…
- In a Fenwick tree with n = 16, an update at index 5 moves i ← i + (i & −i) while i ≤ n. How many tree nodes does the update touch?
- Brian Kernighan's loop (x &= x − 1 until x is 0) counts the set bits of x. What is the total number of loop iterations when it is run once…
- How many integers x in [0, 1023] have no two adjacent 1 bits in their 10-bit binary form?
- In [1, 2, 1, 3, 2, 5] exactly two values appear once and every other value appears twice. Which two values are they?