Amazon Interview Question
SDE-2sCountry: India
Interview Type: In-Person
For each node:
Make the current node as receiver node, publish data from all other nodes to the receiver node parallely.
Few questions:
a. Are nodes ordered in some way? I mean, do nodes know what is the next node in line?
b. What are the various constraints?
1. Node can't send data while receiving.
2. Node can't receive data in parallel from multiple source? --> Is this also a constraint?
c. What is the communication protocol? Broadcast or peer to peer transfer?
Here it goes.
- hprem991 May 24, 20141> For each node in the list, sum up the value of the total list. i.e. Sum = sum + node-> value.
2> For each node in the list, value at the current node is the total sum minus , Node's value. node->value = Sum - node->value.
Time Complexity = O(n) + O(n) = O(n)
Space = constant one variable.