J.P. Morgan Interview Question

Leetcode easy/medium, used java for it. Both questions DP