Loading...
You are given an integer target and arrays positions and speeds, each of length n. n points sit on a number line and all move right toward the same coordinate target. Point i starts at positions[i] (all starts are distinct and less than target) and moves at a constant speed of speeds[i] units per second.
A point can never pass the point ahead of it: if it catches up before or at target, it slows to the front point's speed and the two continue together as a single group. A group is one point or several points traveling together; a point that catches a group exactly at target still joins that group.
Return the number of distinct groups that arrive at target.
Input: target = 12, positions = [10,8,0,5,3], speeds = [2,4,1,1,3]
Output: 3
Explanation: The points starting at 10 and 8 meet exactly at 12 and arrive as one group. The point from 0 never catches anyone. The points from 5 and 3 meet at coordinate 6 and finish together at the slower speed.
Input: target = 10, positions = [3], speeds = [3]
Output: 1
Input: target = 100, positions = [0,2,4], speeds = [4,2,1]
Output: 1
Explanation: The points from 0 and 2 merge at coordinate 4, then that group catches the point from 4 at coordinate 6, so all three arrive together.
n == positions.length == speeds.lengthtarget ≤106positions[i] < targetpositions are distinct.speeds[i] ≤106Click "Run" to test with sample cases or "Submit" to run all tests.