C++ solution throws bad alloc


#1

Comment body goes here.


#2

set B to be the minimum of A.size() and B.When B is bigger than A.size() then we are just simply copying the values we have calculated above;


#3

Always we need just the above dp array, so we can solve the problem using 2 arrays


#4

But, can you tell why c++ throws bad alloc error?..It runs fine when custom tested…