QUESTION

Text
Image

# The Abandoned City You bought a virtual reality glasses. There is only one game installed to it called "The Abandoned City". You are lost in an abandoned city. In order to escape, You have to pay a number of golden coins. So, you decided to collect the gold in the houses of that cit straight line. Each house contains a specific amount of golden coins. You need to figure out the shortest distance you have to walk until you collect the needed amount of golden coins to get out. Note: You can start from any house $i$ and continue your as $i$ to $i+1$ or $i$ to $i$ - 1 but you can't change your direction, and stop at any house. Example Let's assume that the number of houses is 5 and coins in those houses are $[1,2,3,4,5]$ and target is 7. It can be seen that to collect 7 coins you will have to travel through atleast 2 houses. The possible travel options are:- 1. Start from $3^{r d}$ house, travel right and stop at $4^{t h}$ or start from $4_{4}$ th house, travel left and stop at $3^{r d}$ house, thus collecting 7 coins. 2. Start from $4^{t h}$ house, travel right and stop at $5^{t h}$ or start from $5^{t h}$ house, travel left and stop at $4^{t h}$ house , thus collecting 11 coins. Thus the shortest distance you have to walk until you collect 7 golden coins is 2 . Function description solve fast please  