I was given this question as a challenge for a company and I wasn\'t able to solve it. I think that it can be solved by dp but I cannot come up with a algorithm. I will really a