JPMorganChase Interview Question

two coding questions, like leetcode