Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?
- A. 1
- B. 0
- C. 2
- D. 3
Correct answer: B. 0
Brute force over subarrays with running sums checks each one. Prefix sums with a hash map give the same count, since subarrays summing to zero have equal boundary prefix sums.
More Coding Interview Problems questions
- Problem: The mapping of letters is A=1 through Z=26. What is the sum of the values of the letters in the word "MATH"?
- Problem: The number of ways to choose 4 people from 9 so that a specific two people are never both chosen is what value?
- Problem: How many integers in [1, 10^4] are divisible by 3 and have an odd number of digits? Run the code. python print(sum(1 for x in…
- Problem: What is the number of distinct subsets sums obtainable from {2, 3, 7} (including the empty subset)? Run the code. python from…
- Problem: What is the largest prime factor of 2^20 - 1? Run the code. python n = 2 20 - 1 f = 2 last = 1 while f f <= n: while n % f == 0…
- Problem: How many numbers in [1, 500] are not divisible by 2, 3 or 5? Run the code. python print(sum(1 for x in range(1, 501) if x % 2 and…