Solution for C002

I was trying problem C002 from recently concluded Code It Up and could not see how to solve it. I have seen a couple of “Accepted” solutions but they all fail on the below test case:

we wer

Submissions upon which I tested the above test case:

19056378, 19056865, 19060927, 19062256(my own accepted code :P)

EDIT: Problem link:

1 Like

Yes a lot of accepted solutions will fail for such queries as they followed greeady approach.

To be very frank its a copied problem with only modified problem statement it is very popular DP Word break problem.

I think this accepted solution of @raja1999 will work as it used DP.

Solution link :