BackmediumUncategorized uncategorized medium

Subset Essence Target Solution

Problem Statement

You are given an array of integers `essenceValues` and a target essence value `target`. Determine if it is possible to combine a subset of these essence values to achieve the target essence value.

Example 1
Input
{"essenceValues":[10,20,30,40,900],"target":947}
Output
true

Explanation: The essence values 47 and 900 can be combined to achieve the target essence value of 947, but since 47 is not in the list, we can use 10 + 20 + 30 + 40 + 847, however, 847 is also not in the list. Actually, 900 + 47 is the closest and 47 can be obtained by 40 + 7, but since 7 is not in the list, we look for other combinations and find that 10 + 20 + 30 + 40 + 847 is not possible because 847 is not in the list, so we try 900 + 47, and then try to make 47 using the remaining numbers.

Constraints

  • 1 <= essenceValues.length <= 20
  • -1000 <= essenceValues[i] <= 1000
  • 1 <= target <= 2000
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