Company: cashfree_29oct
Difficulty: medium
Exit Time Problem Description Objects are moving along a table of length tableLength . The position of the i th object is given by position[i] . Its velocity is given by velocity[i] , where 0 at position[i] . The ends of the line is at coordinate 0, and the right end is at coordinate tableLength . A positive velocity moves the object right, and a negative velocity moves left. When two objects collide, their velocities are exchanged. Objects are removed if they move left of coordinate 0 or right of coordinate tableLength . All objects begin moving simultaneously at time 0. The task is to find the time in seconds when the last object exits the line. The answer should be rounded up to the nearest integer, i.e., its ceiling. Notes: No two objects have the same initial position. No object starts at position 0 or tableLength . No object has a velocity of 0. Collisions occur instantly. Examples Example 1: This example illustrates the problem logic with a small set of objects. tableLength = 9