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, 21.06.2019 23:00
Explain briefly why you cannot expect to find a previous version of every file with which you work.
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
Your mom wants to purchase a laptop computer. she said she wants her new computer to be able to play her dvds so she can listen to music and wants to know what type of optical drives will play her disk. which type of drive should she look for?
Answers: 1
question
Computers and Technology, 25.06.2019 03:00
Match the categories in the first column with examples in the second column. 1. good for watching movies 2. maximum power with small size 3. older style mobile devices that may or may not have internet connectivity tablet computer a.)pda b.)smart phone c.)tablet computer
Answers: 1
question
Computers and Technology, 25.06.2019 08:10
What is the relation between information and data?
Answers: 3
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, 25.01.2020 07:31
Questions on the website: 13722360