min = Math.min(min, (24 * 60 - last + first));
To explain it in my words, this is done to handle tests cases like [00:00, 10:00, 23:00] that @shawngao mentioned above. By keep track of the last and the first entry in the boolean array (indexed by minutes), we try to work on the edge cases centered around 12 o'clock. Please correct me if my understanding is incorrect. Thanks!