C# - O(N) using dictionary
csharp\npublic int MinSubarray(int[] nums, int p)\n{        \n\tint sum = 0;\n\tfor(int i = 0; i < nums.Length; i++)\n\t{\n\t\tsum = (sum + nums[i]) % p;\n\t}  
```csharp\npublic int MinSubarray(int[] nums, int p)\n{        \n\tint sum = 0;\n\tfor(int i = 0; i < nums.Length; i++)\n\t{\n\t\tsum = (sum + nums[i]) % p;\n\t}     \n\n\tif(sum % p == 0)\n\t{\n\t\treturn 0;\n\t}\n\n\tDictionary<int, int> remaindersIndex = new Dictionary<int, int>()\n\t{\n\t\t[0] = -1\n\t};\n\n\tint result = nums.Length;\n\tint currentSum = 0;\n\tfor(int i = 0; i < nums.Length; i++)\n\t{\n\t\tcurrentSum = (currentSum + nums[i]) % p;\n\t\tint required = (currentSum - sum + p) % p;\n\n\t\tif(remaindersIndex.ContainsKey(required))\n\t\t{\n\t\t\tint length = i - remaindersIndex[required];\n\t\t\tresult = Math.Min(result, length);\n\t\t}\n\n\t\tremaindersIndex[currentSum] = i;\n\t}\n\n\treturn result < nums.Length ? result : -1;        \n}\n\n```
[]