A wooden plank of length n units is placed horizontally. Several ants are walking on the plank, with each ant moving at a constant speed of
When two ants moving in opposite directions meet, they immediately change their directions and continue moving at the same speed. An ant falls off the plank if it reaches position n while moving right.
Given the integer n and two integer arrays left and right, representing the starting positions of the ants moving left and right respectively, return the moment when the last ant falls off the plank.
Constraints:
n
left.length n
left[i] n
right.length n
right[i] n
left.length right.length n
All values of left and right are unique, and each value can appear only in one of the two arrays.
A wooden plank of length n units is placed horizontally. Several ants are walking on the plank, with each ant moving at a constant speed of
When two ants moving in opposite directions meet, they immediately change their directions and continue moving at the same speed. An ant falls off the plank if it reaches position n while moving right.
Given the integer n and two integer arrays left and right, representing the starting positions of the ants moving left and right respectively, return the moment when the last ant falls off the plank.
Constraints:
n
left.length n
left[i] n
right.length n
right[i] n
left.length right.length n
All values of left and right are unique, and each value can appear only in one of the two arrays.