Company: Zomato_1oct
Difficulty: medium
Last Object 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] , and its velocity is given by velocity[i] , where 0 ≤ i < n . The left end 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 it 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. Function Description Complete the function calculateTime in the editor below. Funct