Given three integers **A, B** and **C**, the task is to find the length of a race track if 3 racers are competing in a race where the first racer beats the second racer by **A** metres, the first racer beats the third racer by **B** metres and the second racer beats the third by **C** metres.

**Examples:**

Input:A = 11, B = 90, C = 80

Output:880

Input:A = 10, B = 20, C = 12

Output:60

**Approach :**

Let X be the length of the race track.

**Case 1:** By the time when the First racer finished the race, distances covered by all the 3 racers are:

First = X, Second = X – A, Third = X – B

Let the time taken by the First racer to finish the race be **T _{1}.**

**Case 2:** By the time when the Second racer finished the race, distances covered by the remaining 2 racers are:

Second = X, Third = X – C

Let the time taken by the Second racer to finish the race be **T _{2}.**

The ratio of the speeds of the Second and the Third racer will be constant in both case 1 and case 2 which implies:

=> ((X – A) / T_{1}) / ((X – B) / T_{1}) = (X / T_{2}) / ((X – C) / T_{2})

=> (X – A) / (X – B) = (X) / (X – C)

=> X^{2}– A*X – C*X + A*C = X^{2}– B*X

=> A*C = (C + A – B)*X

=> X = A*C / (C + A – B)

Below is the implementation of the above program:

## C++

`// C++ Program for the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` `#define int long long ` ` ` `int32_t main() ` `{ ` ` ` `int` `A = 11; ` ` ` `int` `B = 90; ` ` ` `int` `C = 80; ` ` ` ` ` `int` `ans = C * A; ` ` ` `ans = ans / (C + A - B); ` ` ` ` ` `cout << ans << endl; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program for the ` `// above approach ` ` ` `import` `java.util.Scanner; ` ` ` `class` `GFG { ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `a = ` `11` `; ` ` ` `int` `b = ` `90` `; ` ` ` `int` `c = ` `80` `; ` ` ` ` ` `System.out.println(c * a ` ` ` `/ (c + a - b)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program for the ` `# above approach ` ` ` `# Function to get the length ` `# of the race track ` `def` `findlength(a, b, c): ` ` ` `# return the answer ` ` ` `return` `c ` `*` `a` `/` `(c ` `+` `a` `-` `b) ` ` ` `a ` `=` `11` `b ` `=` `90` `c ` `=` `80` ` ` `print` `(findlength(a, b, c)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach ` `using` `System; ` `class` `GFG{ ` ` ` `static` `void` `Main() ` `{ ` ` ` `int` `a = 11; ` ` ` `int` `b = 90; ` ` ` `int` `c = 80; ` ` ` ` ` `Console.WriteLine(c * a / (c + a - b)); ` `} ` `} ` ` ` `// This code is contributed by divyeshrabadiya07 ` |

*chevron_right*

*filter_none*

**Output:**

880

**Note:** This is an interview question asked at **POSTMAN (SDE Internship)**

## Recommended Posts:

- Unreachable statement using final and non-final variable in Java
- Aptitude | Race | Question 2
- Aptitude | Race | Question 4
- Aptitude | Race | Question 5
- Program to find the head start in a race
- Puzzle | Who wins the race on a square field ABCD of 40 acres
- Distance of chord from center when distance between center and another equal length chord is given
- Minimum Manhattan distance covered by visiting every coordinates from a source to a final vertex
- Calculate the Square of Euclidean Distance Traveled based on given conditions
- Count paths with distance equal to Manhattan distance
- Distance between centers of two intersecting circles if the radii and common chord length is given
- Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
- Python | Split list of strings into sublists based on length
- Final cell position in the matrix
- Find the final X and Y when they are Altering under given condition
- Find the final radiations of each Radiated Stations
- Minimum possible final health of the last monster in a game
- Find the final sequence of the array after performing given operations
- Find the final number obtained after performing the given operation
- Find the final co-ordinates reached by following a sequence of directions

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.