Best Java Submission with 100% beat
Intuition\n>  Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n\n# Complexity\n- T
# Intuition\n> <!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n18 ms with 100% beat\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n83% beat\n![Screenshot 2023-10-07 121226.png](https://assets.leetcode.com/users/images/24dcd0d2-fe76-4711-a06d-c69d205d17c3_1696660969.7270362.png)\n\n# Code\n```\nclass Solution {\n    public int minSubarray(int[] nums, int p) {\n        int n = nums.length;\n        double sum = 0;\n        for (int i : nums)\n            sum += i;\n        if (sum % p == 0.0)\n            return 0;\n        HashMap<Integer, Integer> mh = new HashMap<>();\n        sum %= p;\n        int s = (int)(sum);\n        int len = n, mod = 0;\n        for (int i = 0; i < n; i++) {\n            if (len == 1)\n                return 1;\n            mod = (nums[i] + mod) % p;\n            mh.put(mod, i);\n            if (s == mod)\n                len = Math.min(i + 1, len);\n            if (mh.get((mod + p - s) % p) != null) \n                len = Math.min(len, i -  mh.get((mod + p - s) % p));\n        }\n        if(len==n)\n            return -1;\n        return len;\n    }\n}\n```
['Java']