subject

Aladdin and his Carpet Aladdin wants to travel around the world and will choose a circular path to fly on his magical carpet. The carpet needs enough magic to take him from one place to another. He knows that after traveling some distance, he can find a magic source that will enable the carpet to travel a further distance. There are n magical sources along the circular path numbered from 0 to n-1. Initially, the carpet has no magic and Aladdin can use a portal to jump to any magical source and start his journey. The carpet consumes units of magic equal to the units of distance travelled. He needs to choose a point to start his journey that will allow him to complete his journey. Determine the lowest index of the starting points from which Aladdin can start his journey and visit all of the places in the circular path in order. If there is no solution, return -1
For example, there are n 4 sources of magic along his route: magic [3, 2, 5, 4] and dist [2, 3, 4, 2]. The first attempt is starting at the first source, magic[0] = 3. He transports there without cost and collects 3 units of magic. The distance to the next point is dist[0] = 2. It takes 2 units of magic to get there and he collects magic[1] = 2 units upon arrival, so he has 3 - 2 2 3 units of magic after making his first carpet ride. Continuing along the journey:
3-dist[11magic[2] = 3 - 3 5
5 5-dist(2]magic[3] = 5 - 4 + 4=5
5-dist[3] 5-2 3
At this point, he is back to the first source. Because he can complete his journey starting at source magic[0], there is no reason to continue with the analysis so its index, 0, is returned. To illustrate a point from the same example, if he starts at position 2, where magic[1] 2 and dist[1] 3, he will not be able to proceed to the next point because the distance is greater than his magic units. Note that the list is circular, so from magic[3] in this example, the next source on the path is magic[0].
Function Description
Complete the function optimal Point in the editor below. The function must return an integer that denotes the minimum index of magic from which he can start a successful journey. If no such starting point exists, return -1
optimalPoint has the following parameter(s):
magic[magic[0],...magic[n-1]: an array of integers where magicli] denotes the amount of magic in the ith source.
dist[dist(01,..dist[n-1]}: an array of integers where dist[i] denotes the distance to the next magical source.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 04:31
Which of the following is not a way in which trees benefit the environment? a. they remove a significant amount of carbon dioxide from the atmosphere. b. they remove a significant amount of oxygen from the atmosphere. c. their roots hold soil in place, reducing rates of erosion. d. they remove ozone and particulates from the atmosphere. select the best answer from the choices provided a b c d
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut off on an hev are both colored orange
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Where can page numbers appear? check all that apply. in the header inside tables in the footer at the bottom of columns at the top of columns
Answers: 1
You know the right answer?
Aladdin and his Carpet Aladdin wants to travel around the world and will choose a circular path to f...
Questions
question
Mathematics, 04.11.2020 18:00
question
Arts, 04.11.2020 18:00
question
English, 04.11.2020 18:00
question
Spanish, 04.11.2020 18:00
Questions on the website: 13722367