Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Dorothy has been caught up in a cyclone and has reached the Munichkin kingdom in the magical land of Oz . On her way, she
Dorothy has been caught up in a cyclone and has reached the Munichkin kingdom in the magical land of Oz On her way, she comes across a yellow brick road across which, she can see the towering castle of the great wizard. The brick road, however, requires a test of the mind to cross it It has been set up by the wizard so that unworthy people may not enter his castle.
The yellow brick road can only be crossed in the following way:
There are N bricks and each brick is labeled with a random number from to
Dorothy is on the th brick and needs to reach the Nth brick.
If she is on the ith brick with value V then she can move to the ith brick, ith brick or any brick with the same value V
There are N bricks and each brick is labeled with a random number from to
Dorothy is on the th brick and needs to reach the Nth brick.
If she is on the it brick with value V then she can move to the ith brick, ith brick or any brick with the same value V
Help Dorothy cross the golden brick road in the smallest number of moves.
Input format:
Line : N number of bricks.
Line : Space separated array representing the numbers on each brick.
Output Format:
Your program should print the smallest number of moves to cross the brick road.
Examples:
Example :
Line :
Line :
Output:
Explanation:
Since the value at Oth position is same as at th position, Dorothy directly moves to the end position. The number of moves is
Example :
Line :
Line :
Output:
Explanation:
The shortest path is position ththth The number of moves is
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started