Reference no: EM132348209
Assignment -
The fulfillment builder will provide an estimate about the time it will take for the item to be created based on the size of each of the parts.thw worker can only combine two parts at a time. The time required to put two parts together is equal to the sum of the parts sizes. The size of the newly constructed part is also equal to the sum of the part's sizes. This process is repeated until of the parts have been merged together to form the final product.
Write an algorithm to output the minimum possible time to put the n parts together and build the final product.
Input
The input to the faction/method consists of two arguments:
numOfParts ,an integer representing the number of the parts;
parts,alist of integers representing the size of the parts.
Output - Return an integer representing the minimum time required to assemble all the parts.
Constraints
2<=numOfParts<=10^6
1<=parts[i[<=10^6
0<=i<=numOfParts
Example -
input:
numOfParts=4
parts=[8,4,6,12]
output:
56
Explanation: The optimal way to merge the sub files is as follows:
Step 1: Assemble the parts of size 4 and 6 (time required is 10). Size of remaining parts after merging [8,10,12].
Step 3:Assemble the parts of size 18 and 12 (time required is 30).
Total time required to assemble the parts is 10+18+30=58.
Code:
import java.util.list
public clss Solution{
int minimumTime(int numOfParts,List<Integer> parts)
{
//write your code here
}
}