Problem · Dynamic Programming

Subset Sum Possible

Learn this problem
MediumAppleONSITE INTERVIEW

Problem statement

You are given an integer array arr and an integer target. Return true if some subset of arr has sum exactly target; otherwise return false.

Each array element may be used at most once.

Function

isSubsetSum(arr: int[], target: int) → boolean

Examples

Example 1

arr = [3,34,4,12,5,2]target = 9return = true

The subset [4,5] sums to 9.

The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

More Apple problems

drafts saved locally
public boolean isSubsetSum(int[] arr, int target) {
  // write your code here
}
arr[3,34,4,12,5,2]
target9
expectedtrue
checking account