i think the problem can also be solved by DP..
arr is the original array..
final is the array required..
for(i=0;i<n;i++) final[i]=arr[i];
for(i=2;i<=k;i++)
for(j=0;j<n-i+2;j++)
final[i]=max( final[j] , final[j+1]);
initial n-i+2 entries in the array final contains the answer..
time complexity (O(nk))...
correct me if i'm wrong anywhere...
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/XWcOWYyt8B0J.
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.