# Page







### failed version

````
```java
class Solution {
    public int minSubarray(int[] nums, int p) {
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        int target = sum % p;
        Integer[] memo = new Integer[p+1];
        return dfs(nums, target, memo);
    }
    private int dfs(int[] nums, int target, Integer[] memo) {
        if (target == 0) {
            return 0;
        }
        if (target < 0) {
            return -1;
        }
        if (memo[target] != null) {
            return memo[target];
        }
        int result = nums.length;
        for (int num : nums) {
            int res = dfs(nums, target - num, memo);
            if (res != -1) { 
                result = Math.min(result, res+1);
            }
        }
        return memo[target] = result;
    }
}

/**
sum = 10
remove 4 -> ans is 1
so it's 6


 9. 16. 18

 3 3 3 p = 6

this is not working! because question is asking "subarray"!!!!!
 */
```
````
