BackmediumBacktracking Microsoft

Asteroid Mining Combinations Solution

Problem Statement

Find all unique combinations of asteroids that sum up to a target value, with no asteroid mined more than once and each asteroid type mined as many times as it appears in the input.

Example 1
Input
[15, 12, 10, 7, 5, 3, 2, 1]
Output
[[15], [12], [10], [7], [5], [3], [2], [1]]

Explanation: Step-by-step: We start with the input [15, 12, 10, 7, 5, 3, 2, 1]. We want to find all unique combinations of these numbers that sum up to 27. We can start by selecting the largest number, 15, which is less than or equal to 27. We can then recursively find combinations of the remaining numbers that sum up to 12. We continue this process until we find all combinations that sum up to 27.

Example 2
Input
[10, 7, 5, 3, 2, 1]
Output
[[10], [7], [5], [3], [2], [1]]

Explanation: Step-by-step: We start with the input [10, 7, 5, 3, 2, 1]. We want to find all unique combinations of these numbers that sum up to 27. We can start by selecting the largest number, 10, which is less than or equal to 27. We can then recursively find combinations of the remaining numbers that sum up to 17. We continue this process until we find all combinations that sum up to 27.

Constraints

  • The number of asteroids will not exceed 10.
  • The target number of gems will be between 1 and 100.
  • Each asteroid contains between 1 and 50 gems.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free