Given the no. of working hours of N people individually to complete a certain piece of work. The task is to find the number of hours they will take when all work together.
Input: n = 2, a = 6.0, b = 3.0 Output: 2 Hours Input: n = 3, a = 6.0, b = 3.0, c = 4.0 Output: 1.33333 Hours
- If a person can do a piece of work in ‘n’ days, then in one day, the person will do ‘1/n’ work.
- Similarly If a person can do a piece of work in ‘m’ days, then in one day, the person will do ‘1/m’ work.
- So on…. for other persons.
So, total work done by N persons in 1 day is
1/n + 1/m + 1/p…… + 1/z
Where n, m, p ….., z are the number of days taken by each person respectively.
The result of the above expression will be the part of work done by all person together in 1 day, let’s say a / b.
To calculate the time taken to complete the whole work will be b / a.
Consider an example of two persons:
Time taken by 1st person to complete a work = 6 hours Time taken by 2nd person to complete the same work = 2 hours Work done by 1st person in 1 hour = 1/6 Work done by 2nd person in 1 hour = 1/2 So, total work done by them in 1 hour is => 1 / 6 + 1/ 2 => (2 + 6) / (2 * 6) => 8 / 12 So, to complete the whole work, the time taken will be 12/8.
Note: Here the input array contains hours, it can be days, minutes……so on.
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.