Java O(N)
find sub array with sum == sum(nums) % p;\nUse strategy of prefix sum, remainder, and 2 sum hashMap.\n\n\n    public int minSubarray(int[] nums, int p) {\n     
find sub array with sum == sum(nums) % p;\nUse strategy of prefix sum, remainder, and 2 sum hashMap.\n\n```\n    public int minSubarray(int[] nums, int p) {\n        int n = nums.length, res = Integer.MAX_VALUE;\n        long acc[] = new long[n + 1];\n        for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + nums[i];\n        if (acc[n] < p) return -1;\n        long rmv = acc[n] % p; // need to find subarray with sum, where sum % p == rmv;\n        if (rmv == 0) return 0;\n        Map<Long, List<Integer>> map = new HashMap<>();\n        for (int i = 0; i < n + 1; i++) {\n            long rem = acc[i] % p, tgt = (rem + p -rmv) % p;\n            if (map.containsKey(tgt)) res = Math.min(res, i - map.get(tgt).get(map.get(tgt).size() - 1));\n            map.computeIfAbsent(rem, k -> new ArrayList<>());\n            map.get(rem).add(i);\n        }\n        return res == n || res == Integer.MAX_VALUE ? -1 : res; // can not remove the whole array, or did not find answer.\n    }\n```
[]