Panda Guru LogoPanda
Guru

Amazon Online Assessment Question 2024 November

Round 1

Questions: Amazon Web Services has n servers lined up in a row. The th server has the capacity of capacity[i]. Any application can be deployed on a balanced contiguous subsegment of 3 or more servers.

A contiguous segment [l, r] of servers is said to be balanced if capacity[l] = capacity[r] = sum(capacity[l+1]... capacity[r-1]] i.e. the capacity of the servers at the endpoints of the segment should be equal to the sum of the capacity of all the interior servers.

Given the capacity of each server in a row, find the number of balanced subsegments in it.

Example

capacity = [9, 3, 3, 3, 9]
Return 2, the number of balanced subsegments
capacity = [9, 3, 1, 2, 3, 9, 10]
returns 2 -> Explanation
The balanced subsegments are: [9, 3, 1, 2, 3, 9] and [3, 1, 2, 3].
capacity = [6, 1, 2, 3, 6]
Sample Output: 1
The only balanced subsegment is [6, 1, 2, 3, 6].

Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.