JPMorganChase Interview Question

My coding test was similar to TwoSum problem