Program to find the head start in a race
Given the head start that A gives to B and C in a 100-meters race. The task is to find the head-start that B can give to C in the same race.
Input: B = 10 meters, C = 28 meters Output: 20 meters B can give C a start of 20 meters. Input: B = 20 meters, C = 50 meters Output: 62 meters B can give C a start of 62 meters.
Total meters in a race = 100 meters.
A is ahead of B by 10 meters. When A completed it’s 100 meters B completed it’s 90 meters.
Similarly, A is ahead of C by 28 meters. When A completed it’s 100 meters C completed it’s 72 meters.
Now, When B completed it’s 90 meters C completed it’s 72 meters.
So when B completed it’s 100 meters C completed it’s 80 meters.
–> (( C * 100) / B)
–> (( 72 * 100) / 90) i.e 80 meters
So B can give C a start of 20 meters
Below is the implementation of the above approach:
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.