Got this coding question in Technical Round-1 of Komprise India.
There are several lampposts on the road. The list lampPositions contains position of each lamp and is sorted. The list lightingRange contains range of each lamppost. The range of i'th lamp with position lampPositions[i] is equal to lightingRange[i]. Each lamp covers a certain range and the range of the lampposts can overlap also. Due to overlapping ranges, the power is being wasted. We need to remove the extra lampposts so that power is saved. Find the maximum lampposts which can be removed.
Ex. Given input: lampPositions = [-9, -6, -5, -2, 1, 3, 4, 12] and lightingRange = [5, 3, 9, 1, 1, 4, 2, 3].
Output: 5
Explanation: By removing the lamps covered by the lamppost at 3rd position, we can remove 5 extra lamps which are not required.
Any idea, how to approach this question and solve this. I was not able to solve it. I thought of overlapping intervals or sliding window. This was my first Tier-1 company interview and got rejected due to this question. : (