Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | May 2017 |
Last Sign in: | 307 Weeks Ago, 4 Days Ago |
Questions Answered: | 66690 |
Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
N cars are racing on a straight road. You are given their position and velocity at time t = 0. Each car is moving in the same direction with a constant positive velocity. Find the number of overtakes that take place in the race, if the race ends at time t = T0.
A car A is said to have overtaken a car B if there exists a time t0 such that car A was strictly behind car B for time 0 0 but is strictly ahead of car B for time T0 >= t > t0
Input: 2 3 5 1 3 2 2 1 1 4 2 1 2 1 4 2 2 4 1 Output: 1 2
Example case 1. The first car will overtake the second car at time 1.
Example case 2. The second car will overtake the third car at time 0.5 and the second car will overtake the fourth car at time 1. We count these towards the answer. The first car overtakes the fourth car at time 3 and the third car overtakes the fourth car at time 2. We do not count these towards the answer.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll