Interviewbit problem help

Revision en1, by aman_naughty, 2019-07-18 18:50:23

Problem link: link

My code

Spoiler

We have 2 choices for each element either + or — I am considering both the choices and then picking the optimal one. In the code the dp[i].first = the minimum number of sign inversions dp[i].second = the optimal sum we achieve by either inverting this one or not;

It fails on array 10 4 3 2 1

Can someone point out why my aaproach is wrong?

Tags #dp, #interview, #beginner, #help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English aman_naughty 2019-07-18 18:50:23 1183 Initial revision (published)