eBay interview question

It is a DP problem for LC, probably LC medium difficulty.