Trains the technique from
LeetCode 853Car FleetThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Loaded barges work their way along a single-file canal reach toward a lock. The lock stands lock metres from the top of the reach. Barge i starts starts[i] metres from the top of the reach and covers paces[i] metres a minute in clear water. No two barges start from the same distance, and all of them are under way at minute 0.
The reach is too narrow to pass. If a barge closes right up on the barge ahead, it has to throttle back and hold that barge's pace from then on, and the two carry on to the lock together as a single raft; a raft holds the pace of the slowest barge in it, and rafts join other rafts the same way. Barges that reach the lock at exactly the same minute count as one raft, whether or not they were travelling together before that.
Return how many rafts pass the lock gate.
Example 1
The barge starting 6 metres along needs 6 minutes to reach the lock and the one starting at the head needs 6 minutes as well, so they get there together and are counted once.
Example 2
The barge at 35 metres reaches the lock 15 minutes in. The other two are held up behind it on the way and pass the lock gate with it.
Example 3
The barge at 25 metres arrives after 1 minute on its own. The barge at 10 metres arrives 20 minutes in, with the barges from 5 and 0 metres held behind it.
Example 4
All three barges hold the same pace, so none of them ever closes on the one in front and each reaches the lock on its own.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def raft_count(lock: int, starts: list[int], paces: list[int]) -> int:public int raftCount(int lock, int[] starts, int[] paces)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.