# Minimum time required to complete a work by N persons together

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.

**Examples:**

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

**Solution:**

- 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 beb / 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.

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to calculate the time ` `float` `calTime(` `float` `arr[], ` `int` `n) ` `{ ` ` ` ` ` `float` `work = 0; ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `work += 1 / arr[i]; ` ` ` ` ` `return` `1 / work; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `float` `arr[] = { 6.0, 3.0, 4.0 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` ` ` `cout << calTime(arr, n) << ` `" Hours"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation ` `// of above approach ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to calculate the time ` `static` `double` `calTime(` `double` `arr[], ` `int` `n) ` `{ ` ` ` `double` `work = ` `0` `; ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) ` ` ` `work += ` `1` `/ arr[i]; ` ` ` ` ` `return` `1` `/ work; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `double` `arr[] = { ` `6.0` `, ` `3.0` `, ` `4.0` `}; ` ` ` `int` `n = arr.length; ` ` ` ` ` `System.out.println(calTime(arr, n) + ` ` ` `" Hours"` `); ` `} ` `} ` ` ` `// This code is contributed ` `// by inder_verma. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of ` `# above approach ` ` ` `# Function to calculate the time ` `def` `calTime(arr, n): ` ` ` ` ` `work ` `=` `0` ` ` `for` `i ` `in` `range` `(n): ` ` ` `work ` `+` `=` `1` `/` `arr[i] ` ` ` ` ` `return` `1` `/` `work ` ` ` `# Driver Code ` `arr ` `=` `[ ` `6.0` `, ` `3.0` `, ` `4.0` `] ` `n ` `=` `len` `(arr) ` ` ` `print` `(calTime(arr, n), ` `"Hours"` `) ` ` ` `# This code is contributed ` `# by Sanjit_Prasad ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation ` `// of above approach ` `using` `System; ` `class` `GFG ` `{ ` ` ` `// Function to calculate the time ` `static` `double` `calTime(` `double` `[]arr, ` ` ` `int` `n) ` `{ ` ` ` `double` `work = 0; ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `work += 1 / arr[i]; ` ` ` ` ` `return` `Math.Round(1 / work, 5); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main () ` `{ ` ` ` `double` `[]arr = { 6.0, 3.0, 4.0 }; ` ` ` `int` `n = arr.Length; ` ` ` ` ` `Console.Write(calTime(arr, n) + ` ` ` `" Hours"` `); ` `} ` `} ` ` ` `// This code is contributed by Smitha ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function to calculate the time ` `function` `calTime(&` `$arr` `, ` `$n` `) ` `{ ` ` ` `$work` `= 0; ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `$work` `+= 1 / ` `$arr` `[` `$i` `]; ` ` ` ` ` `return` `1 / ` `$work` `; ` `} ` ` ` `// Driver Code ` `$arr` `= ` `array` `(6.0, 3.0, 4.0); ` `$n` `= sizeof(` `$arr` `); ` ` ` `echo` `calTime(` `$arr` `, ` `$n` `); ` `echo` `" Hours"` `; ` ` ` `// This code is contribuuted ` `// by Shivi_Aggarwal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

1.33333 Hours

**
Note:** Here the input array contains hours, it can be days, minutes……so on.

## Recommended Posts:

- Minimum operations of the given type required to make a complete graph
- Minimum time required to fill a cistern using N pipes
- Time taken by two persons to meet on a circular track
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Minimum time to reach a point with +t and -t moves at time t
- Time required to meet in equilateral triangle
- Minimum Players required to win the game
- Minimum number of given operation required to convert n to m
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum operations required to change the array such that |arr[i] - M| <= 1
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum inversions required so that no two adjacent elements are same
- Minimum number operations required to convert n to m | Set-2
- Minimum number of operations required to reduce N to 1

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.