glow's blog

By glow, history, 8 years ago, In English

Hi, I was solving Hard Problem and my approach is :

If string[i] <= string[i+1] than continue;

Else :

    If  string_rev[i] < string[i+1] c1=cost[i] Else c1=inf;

    If string[i] < string_rev[i+1] c2=cost[i+1] Else c2=inf;

    If string_rev[i] < string_rev[i+1] c3=cost[i]+cost[i+1]; Else c3=inf;

    if(c1<=c2 && c1<=c3 && c1!=inf) ans+=c1; If(c1==c2)a[i+1]=min(a[i+1],b[i+1]);;

    else if(c2<=c1 && c2<=c3 && c2!=inf) ans+=c2; a[i+1]=min(a[i+1],b[i+1]);

    else if(c3<=c1 && c3<=c2 && c3!=inf) ans+=c3; a[i+1]=min(a[i+1],b[i+1]);

Code Link.

Can you please help me in finding fault in this approach ?

  • Vote: I like it
  • -1
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

try this tc: 4

1 3 5 7

aa

za

ay

ab