J.P. Morgan interview question

Leetcode easy/medium from 3rd party. Timed