Find invalid transactions in time-sorted input | Bloomberg Interview Question