The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
A DVD Store has just put up "Interstellar" DVD/Blu-Ray discs on their shelf for sale. N people are waiting outside the store in a queue to grab their copy.They are given tickets which has a number x printed on it. The number denotes the Serial Number of the DVD they should take and proceed to the checkout. The number printed on the tickets are in no particular order.
The store has the checkout section at the beginning of the shelf.
Â
There are N DVD's on the shelf at the store.Initially the serial number of the DVD's are in the order from 1 to N.The DVD with serial number x is at a distance of x units from the checkout section of the DVD store.When the store opens first person enters, moves to the DVD which has the serial number equal to his/her ticket number, takes it from the shelf and moves to the checkout section.After taking the DVD, all the DVD's which has serial numbers greater than the currently taken DVD and still present in the shelf, move 1 unit up the shelf to close the gap created by the removed DVD.All N people claim their DVD's from the store.
Â
Your task is to print the distance traveled by all N people to get his/her DVD copy. (Do not include the return distance to the checkout section).
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Input: 1 5 2 3 1 4 5 Output: 2 2 1 1 1
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