Practice/ServiceTitan/Leetcode 2766. Relocate Marbles
CodingMust
You are managing a warehouse where boxes are placed at various positions along a long conveyor belt. Each position is represented by an integer coordinate. Initially, you have boxes at specific positions given in the boxes array.
You need to perform a series of reorganization operations. Each operation is defined by two arrays: moveFrom and moveTo. For the i-th operation, you must take all boxes currently at position moveFrom[i] and relocate them to position moveTo[i].
After completing all operations in sequence, return a sorted array of all positions that contain at least one box.
boxes are unique (initially no position has multiple boxes)Example 1:
` Input: boxes = [1, 3, 5], moveFrom = [1, 5], moveTo = [2, 6] Output: [2, 3, 6] Explanation:
Example 2:
` Input: boxes = [1, 2, 3], moveFrom = [1, 2, 3], moveTo = [5, 5, 5] Output: [5] Explanation:
Example 3:
Input: boxes = [1], moveFrom = [1, 3, 5], moveTo = [3, 5, 7] Output: [7] Explanation: Single box moves through chain: 1→3→5→7