Pergunta de entrevista da empresa eBay

2 leetcode type coding question, but not from leetcode directly. The first one was supposed to be warm up, but interviewer pressed on getting to the most optimal solution and spent majority time there. Was not able to solve the actual question which was a DP problem.