'HashMap' 'Prefix Sum' 'Java'
\nFor proper explaination check - \nhttps://leetcode.com/problems/make-sum-divisible-by-p/discuss/2282512/Java-or-Prefix-Sum-and-HashMap-or-With-comments-and-ex
```\nFor proper explaination check - \nhttps://leetcode.com/problems/make-sum-divisible-by-p/discuss/2282512/Java-or-Prefix-Sum-and-HashMap-or-With-comments-and-example\n \nclass Solution {\n    public int minSubarray(int[] arr, int k) {\n        \n        long sum = 0;\n\t\tint Rem = 0;\n    \n        for (int j = 0; j < arr.length; j++)\n            sum += arr[j];\n        \n        if (sum % k == 0)\n         return 0;\n\t\t\n\t\t Rem = (int) (sum % k);\n\t\t\n        HashMap<Integer, Integer> map = new HashMap<>();\n        map.put(0, -1);\n        \n        sum = 0;\n        int res = arr.length;\n        \n        for (int i = 0; i < arr.length; i++) {\n            sum += arr[i];\n            int curRem = (int)(sum % k);\n            \n           int toFind = curRem - Rem;\n            \n            if (toFind < 0)\n            toFind += k;\n            \n            if (map.containsKey(toFind)){\n                res = Math.min(res, i - map.get(toFind));\n\t\t\t  }\n                else{\n            map.put(curRem, i);\n\t\t\t}\n        }\n        if (res == arr.length)\n            return -1;\n        \n        return res;\n    }\n}\n```\n
[]