Monday, March 28, 2011

WAP Find Minimu Number of Jumps to Reach In The End , In An UnSorted Array

#include
#include

int main()
{

int arr[] = {1 ,3, 5, 8 ,9 ,2, 6,7, 6, 8, 9};//{1, 3, 6, 0, 0, 3, 2, 3, 6, 8, 9};
int size=11;

int step=0,jump=0;
int i=0,j=0,max=0;

while( i< size)
{
jump++;
max=0;
step=0;

/*computes max distance it can cover in this jump*/
for(j=1;j<=arr[i];j++)
{
if(arr[i+j]+j>max)
{
max=arr[i+j]+j;
step=j;
}
}
i=i+step;
}

printf ( " %d ",jump);



return 0;
}

No comments :