Data Structures & AlgorithmsHardAmazon OA · Arrays
How many contiguous subarrays of [3, 4, 7, 2, -3, 1, 4, 2] have a sum of exactly 7?
- A. 3
- B. 5
- C. 4
- D. 6
Correct answer: C. 4
With prefix sums and a hash map the matching subarrays are [3,4], [7], [7,2,-3,1] and [1,4,2], so 4.
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 length of the shortest substring of "AXBYAZCBAB" that contains at least two A's, at least one B and at least one C?
- Seven people numbered 1 to 7 stand in a circle (a circular linked list). Counting starts at person 1, and every 3rd person is removed…
- What is the area of the largest rectangle in a histogram with bar heights [3, 6, 5, 7, 4, 8, 1, 0, 6] and unit width?
- What is the maximum sum of a non-empty contiguous subarray of [3, -4, 2, -3, -1, 7, -5] if you may delete at most one element from the…
- How many contiguous subarrays of [2, 3, 4, 1, 5, 2, 6] have a product strictly less than 50?
- How many contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 5?