Hey Samba,
Check this solution
dp[i][j]= cost required to get the sorted sequence from index i to index j

dp[i][j]= min(dp[i+1][j] + (i-j)*indexof(i) in the sequence ,dp[i][j-1] +
(i-j) *indexof(j) insequence)

Since the current state depends on only previous 2 states so you can
optimize space to O(n) .

Thanks
Rahul

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

Reply via email to