unknown Interview Question for Software Developers
- 1of 1 vote
AnswerYou are given a list of tasks as an integer array, task_costs. Every i-th element of task_costs represents a task and requires task_costs[i] seconds to complete. All tasks listed in the array are independent of other tasks.
- Abhishek.Mathur.CA September 18, 2016 in United States
It is required to finish all the tasks independently and as soon as possible. You are given a single worker robot to start taking the tasks and finish them one at a time. However if you like, you can divide the worker robot in two. Each resulting robot can then be further divided into two and so on. There is a cost, in seconds, of dividing a robot in two, represented by robot_divide_cost.
You can assign an independent task to any available robot, however you can't interrupt or divide a robot while it is working on the assigned task. At the same time you can't assign a task to any robot while its in the process of getting divided.
To keep things simple you can't allow multiple robots to work on the same task. At any given time only one robot can work on a task and finish it. Once any particular robot finishes a task it can't be assigned any further tasks.
Given a list of tasks and cost of dividing a robot, find the least amount of time to finish all tasks.
Input:
3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,360,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600
3600
Expected Output: 25200
Input:
1113,773,824,822,1458,1257,908,1320,780,1016,1066,861,1150,718,1405,738,718,980,1037,946,1121,1349,805,1378,1308,1272,1532,779,875,1392,982,1282,744,723,1033,1067,1158,1071,742,683,678,762,686,1143,862,1231,765,1472,1560,1085
3147
Expected Output: 20040| Report Duplicate | Flag | PURGE
unknown Software Developer
Very hard problem here to solve.
We could go greedy on this one or do dynamic programming.
I decided dynamic programming on the board but the more I think about it might easier and cheaper to do it in a greedy algorithm.
In a greedy we can sort the task costs and keep doing task linearly comparing what is cheaper either divide or perform linearly.
Anyway here is my dynamic programming solution:
- Nelson Perez September 19, 2016