← back to unit
Challenge
# queues advanced
The Merry-Go-Round Meetup
Two riders on a carousel of n horses (numbered 0 to n-1). Each minute, rider A jumps sa horses forward and rider B jumps sb. When do they land on the same horse? 🎠
You get n, A's start a and speed sa, B's start b and speed sb (they do meet). Print the first minute (1 or later) they share a horse.
Example:
Input: n = 12, a = 0, sa = 2, b = 6, sb = 1
Output: 6
Each minute A's position is (0 + 2 × minute) % 12 and B's is (6 + 1 × minute) % 12 — they first land on the same horse at minute 6.
💡 need a hint?
q-merry-go-round-meetup.py🔒 given lines are locked — write your code in between
loading...