Company: TrueEstate

Difficulty: medium

Problem Statement

A deep-space tracking station monitors a single straight corridor of debris fragments. The fragments are listed from left to right, so position i in the list is strictly to the left of position i + 1 . Every fragment is described by one non-zero integer a[i] : |a[i]| is the mass of the fragment. The sign is the travel direction: a positive value means the fragment drifts to the right , a negative value means it drifts to the left . All fragments travel at exactly the same speed, so two fragments can only ever meet when the one on the left is moving right and the one on the right is moving left. Fragments travelling in the same direction keep a constant gap forever and never meet. When two fragments meet: the one with the smaller mass is destroyed and disappears; if both masses are equal, both are destroyed; the surviving fragment keeps its mass and direction unchanged and carries on, so it may meet further fragments afterwards. Report the corridor once no further meeting is possible. I

More TrueEstate OA questionsInterview experiences