Greedy algorithm works fine.
- Iterate the weight array from left to right and find out the TOTAL weight. // This step takes O(n) time
- Iterate the weight array again from right to left and find the point at which the accumulated weight meets or exceeds half of total weight. Put the proxy server on that location.
Examples:
Given [1, 1, 1, 1], put the proxy server on the 2nd server
Given [1,2,3,4], put the proxy server on the 3rd server.
Given [1,2,3,10], put the proxy server on the 4th server.
Given [10,1,1,1,1,1,1], put the proxy server on the 1st server.