Data Structures & AlgorithmsModerateProduct Company SDE · array OA
Problem: What is the smallest positive integer missing from [3, 4, -1, 1]? Run the code.
Problem: What is the smallest positive integer missing from [3, 4, -1, 1]? Run the code.
a = [3, 4, -1, 1]
m = 1
while m in a:
m += 1
print(m)What is printed?- A. 5
- B. 1
- C. 2
- D. 3
Correct answer: C. 2
1 is present, so the first missing positive is 2. The linear-time version places values in their index slots instead of searching.
More Coding Interview Problems questions
- Problem: What is the sum of the lengths of all contiguous subarrays of [1, 2, 3]? Run the code. python a = [1, 2, 3] print(sum(len(a[i:j])…
- Problem: What is 6! mod 7, the value predicted by Wilson's theorem for a prime p = 7 (where (p-1)! ≡ -1 mod p, i.e. 6 mod 7)? Run the…
- Problem: How many integers in [1, 50] are divisible by both 2 and 3? Run the code. python print(sum(1 for x in range(1, 51) if x % 2 == 0…
- Problem: What is the sum of the first 10 odd positive integers? Run the code. python print(sum(2 i + 1 for i in range(10))) What is printed?
- Problem: How many 2-digit numbers have both digits odd? Run the code. python print(sum(1 for x in range(10, 100) if int(str(x)[0]) % 2 ==…
- Problem: How many pairs (i < j) of [1, 3, 5, 7, 9] have a[i] + a[j] >= 10? Run the code. python a = [1, 3, 5, 7, 9] print(sum(1 for i in…