Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

You are given an ordered stream of messages where each message is identified by a unique, non-negative offset starting at 0. In a multi-threaded environment, the messages may be processed out of order. However, when committing (acknowledging) a message, the system requires that all messages with lower offsets have already been processed. Below is a detailed description of the commit rules:

Test Cases
Input
Output
Expected