JPMorganChase Interview Question

2 Programming Tasks, somewhat difficult