There are n
Toy cars moving in road and you are given array direction
of size n
where direction[i]
= 1 or -1, 1 means car going to right and -1 means car going to left and array strength
. If two car collide at any point the car with lower strength will Blast and if both cars strength are equal then both will Blast.
Returns how many cars will stay after all possible collision.
Function Description
CarsLeft
has the following parameters:
int n
: The numbers of cars.int[] direction
: The directions of each car.int[] strength
: The strength of each car.
Returns
int[]
: array Lists of Cars left after collisions in non-decreasing order.
Example 1:
Input: n = 3, direction = [1, -1, 1], strength = [5, 3, 2]
Output: [0, 2]
Explanation:Car 0 going right and car 1 going left
strength[0] > strength[1]
. Therefore, when 0 and 1 meet, 1 will Blast.
Example 2:
Input: n = 5, direction = [1, -1, -1, 1, -1, 1], strength = [7, 2, 3, 5, 5, 6]
Output: [0, 4]
Explanation:Both car 2 and 3 will blast when they collide.
n <= 2 * 10^5
direction[i] = 1
ordirection[i] = -1
strength[i] <= 10^9

input:
output: