Tap here to switch tabs
Problem
Submissions

Problem: Count Robot Groups

Try to solve the Count Robot Groups problem.

Statement

There are nn robots positioned on an infinite number line. You are given two integer arrays position and speed, each of length nn, where position[i] and speed[i] represent the starting position and constant speed of the ii-th robot, respectively. You are also given an integer distance.

All robots move in the positive direction. Whenever a robot or a group of robots gets within a distance of at most distance behind another robot or group, they merge into a single group. Once merged, the combined group continues moving with the position and speed of its rightmost robot.

Return the total number of robot groups that will eventually remain.

Constraints:

  • 1≤1 \leq position.length == speed.length ≤105\leq 10^5

  • 1≤1 \leq position[i], speed[i], distance ≤109\leq 10^9

  • position is strictly increasing.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Robot Groups

Try to solve the Count Robot Groups problem.

Statement

There are nn robots positioned on an infinite number line. You are given two integer arrays position and speed, each of length nn, where position[i] and speed[i] represent the starting position and constant speed of the ii-th robot, respectively. You are also given an integer distance.

All robots move in the positive direction. Whenever a robot or a group of robots gets within a distance of at most distance behind another robot or group, they merge into a single group. Once merged, the combined group continues moving with the position and speed of its rightmost robot.

Return the total number of robot groups that will eventually remain.

Constraints:

  • 1≤1 \leq position.length == speed.length ≤105\leq 10^5

  • 1≤1 \leq position[i], speed[i], distance ≤109\leq 10^9

  • position is strictly increasing.