✅ [Solution][Swift] Hash Map, Prefix Sum, O(n)
TC: O(n)\nSC: O(n)\nswift []\nclass Solution {\n    func minSubarray(_ nums: [Int], _ p: Int) -> Int {\n        let n = nums.count\n        var prefixSum = Arra
**TC:** $$O(n)$$\n**SC:** $$O(n)$$\n```swift []\nclass Solution {\n    func minSubarray(_ nums: [Int], _ p: Int) -> Int {\n        let n = nums.count\n        var prefixSum = Array(repeating: 0, count: n + 1)\n        for i in 0..<n {\n            prefixSum[i + 1] = (prefixSum[i] + nums[i]) % p\n        }\n\n        let r = prefixSum[n] % p\n        guard r != 0 else { return 0 }\n\n        var map = [0: 0], result = -1\n        for i in 1...n {\n            if let j = map[(prefixSum[i] - r + p) % p] {\n                result = min(result == -1 ? Int.max : result, i - j)\n            }\n            map[prefixSum[i]] = i\n        }\n        return result == n ? -1 : result\n    }\n}\n```
['Array', 'Hash Table', 'Swift', 'Prefix Sum']