Java Solution using hashmap
\nFind smallest subarray that the sum is X\n\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int length = nums.length;\n        int 
```\nFind smallest subarray that the sum is X\n\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int length = nums.length;\n        int sum = 0;\n        for (int i=0; i<length; i++)\n            sum = (sum + nums[i]) % p;\n        if (sum == 0)\n            return 0;\n        Map<Integer, Integer> map = new HashMap<>();\n        map.put(0, -1);\n        int result = length;\n        int currentSum = 0;\n        for (int i=0; i<length; i++) {\n            currentSum = (currentSum + nums[i]) % p;\n            int difference = (currentSum - sum + p) % p;\n            if (map.containsKey(difference)) {\n                int finalLength = i - map.get(difference);\n                result = Math.min(finalLength, result);\n            }\n            map.put(currentSum, i);\n        }\n        if (result == length)\n            return -1;\n        else\n            return result;\n    }\n}\n```
['Array', 'Java']