1. Collision Detection Algorithm
Given an array of pairs of integers representing coordinates of objects and a square area around its center with a side equal to 2, write a function to calculate the number of object pairs that collide. Two objects are supposed to collide if their collision boxes have at least one common point. Explain how you would implement this function and discuss its time and space complexity.
2. Race Car Elimination Algorithm
Given a two-dimensional string array representing drivers' names and their lap times in seconds, write an algorithm to return the drivers in the order they are eliminated, ending with the last driver or drivers remaining. If multiple drivers are eliminated on the same lap, their names should be listed alphabetically. Provide a solution with time complexity not worse than O(laps.length * laps[0].length), and explain why your solution meets this requirement.
3. Priority Queue Implementation
Describe how you would implement a priority queue. What data structures would you use and why? Discuss the time complexity of the operations involved.
4. Optimal Lamp Placement
There are some objects placed on a number line, and you are given their coordinates in ascending order in an object array. There are no two objects placed at the same position. You need to place a lamp on an integer coordinate on the same line so that it illuminates the maximum number of objects. Return the coordinate of the lamp. For example, if the objects are [-5,3,4,9] and the radius of the lamp is 5, then the output should be -1, because the lamp placed at position -1 can illuminate 3 objects.
5. Command Type Counting
Given a string array with commands in it, their types are 'ls', 'cp', 'mv', and '!'. The '!' command is used to repeat the 'index-th' command (1-based) since the start of the session. You need to return how many times the commands 'ls', 'cp', and 'mv' are called. For example, given the input array (ls, cp, mv, mv, !1, !5), '!1' calls 'ls', and '!5' calls '!1' which in turn calls 'ls', so the return should be 'ls' is called 2 times.