memory effective dp
combined solution
fixed bug with queue