Minimize time for two handlers | Amazon Coding Question