Sort the cargo containers in the spaceship's cargo bay based on their weight. The containers must be separated into two categories: those weighing less than 850 kilograms and those weighing 850 kilograms or more. The order of containers within each category must be maintained as they were initially loaded.
Explanation: Step-by-step: We first initialize two empty lists, lessThanTarget and greaterThanOrEqualToTarget. Then we iterate over the input array. If a container's weight is less than 850 kilograms, we append it to lessThanTarget. If a container's weight is 850 kilograms or more, we append it to greaterThanOrEqualToTarget. Finally, we return the dictionary containing both lists.
Explanation: Step-by-step: We first initialize two empty lists, lessThanTarget and greaterThanOrEqualToTarget. Then we iterate over the input array. If a container's weight is less than 850 kilograms, we append it to lessThanTarget. If a container's weight is 850 kilograms or more, we append it to greaterThanOrEqualToTarget. Finally, we return the dictionary containing both lists.
Master coding challenges related to Arrays and solve the [Backup] Galactic Cargo Sorting problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak