β back to unit
Medium
# breaking it down medium
Two Trains
Two trains on one track, racing toward each other β when do they meet? (Relax, they're toy trains.) ππ
Train A starts at position a moving right sa per second; train B starts at b (further right) moving left sb per second. Print the first whole second when A's position is at or past B's.
Example:
Input: a = 0, sa = 3, b = 12, sb = 1
Output: 3
The gap between them (12) shrinks by 3 + 1 = 4 each second, closing after 12 Γ· 4 = 3 seconds.
π‘ need a hint?
brk-two-trains.pyπ given lines are locked β write your code in between
loading...