Can anyone show me a case where the following greedy algorithm does
not produce the optimal result:

>From position i, if you can move to the end, do it
Otherwise make the legal move to location j which maximizes j+arr[j].

Don

On Jan 25, 11:03 pm, Sanjay Rajpal <[email protected]> wrote:
> Given an array of integers where each element represents the max number of
> steps that can be made forward from that element. Write a function to
> return the minimum number of jumps to reach the end of the array (starting
> from the first element). If an element is 0, then cannot move through that
> element.
>
> Example:
>
> *Input: arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}
> Output: 3 (1-> 3 -> 8 ->9)*
>
> *
> Sanjay Kumar
> B.Tech Final Year
> Department of Computer Engineering
> National Institute of Technology Kurukshetra
> Kurukshetra - 136119
> Haryana, India
> Contact: +91-8053566286
> *

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to