{"id":22513451,"url":"https://github.com/emahtab/subarray-sums-divisible-by-k","last_synced_at":"2026-03-19T23:02:40.976Z","repository":{"id":260407888,"uuid":"881211714","full_name":"eMahtab/subarray-sums-divisible-by-k","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-31T05:45:23.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-23T15:56:46.907Z","etag":null,"topics":["leetcode","prefix-sum"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-31T05:36:15.000Z","updated_at":"2024-10-31T05:45:26.000Z","dependencies_parsed_at":"2024-10-31T06:23:41.692Z","dependency_job_id":"8a06d551-8e86-4af5-8041-8015a02a270e","html_url":"https://github.com/eMahtab/subarray-sums-divisible-by-k","commit_stats":null,"previous_names":["emahtab/subarray-sums-divisible-by-k"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/subarray-sums-divisible-by-k","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fsubarray-sums-divisible-by-k","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fsubarray-sums-divisible-by-k/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fsubarray-sums-divisible-by-k/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fsubarray-sums-divisible-by-k/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/subarray-sums-divisible-by-k/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fsubarray-sums-divisible-by-k/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29181843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T23:15:33.022Z","status":"ssl_error","status_checked_at":"2026-02-06T23:15:09.128Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","prefix-sum"],"created_at":"2024-12-07T03:12:23.544Z","updated_at":"2026-02-07T00:32:11.850Z","avatar_url":"https://github.com/eMahtab.png","language":null,"readme":"# Subarray sums divisible by k\n## https://leetcode.com/problems/subarray-sums-divisible-by-k\n\nGiven an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.\n\nA subarray is a contiguous part of an array. \n```\nExample 1:\nInput: nums = [3,4,1,6,2,5], k = 7\nOutput: 6\nExplanation: There are 6 subarrays with a sum divisible by k = 7:\n[3,4], [1,6], [3,4,1,6], [2,5], [1,6,2,5], [3,4,1,6,2,5]\n\nExample 2:\n\nInput: nums = [4,5,0,-2,-3,1], k = 5\nOutput: 7\nExplanation: There are 7 subarrays with a sum divisible by k = 5:\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n\nExample 3:\n\nInput: nums = [5], k = 9\nOutput: 0\n```\n\n## Constraints:\n\n1. 1 \u003c= nums.length \u003c= 3 * 10^4\n2. -10^4 \u003c= nums[i] \u003c= 10^4\n3. 2 \u003c= k \u003c= 10^4\n\n## Implementation :\n```java\nclass Solution {\n    public int subarraysDivByK(int[] nums, int k) {\n        int runningSum = 0;\n        Map\u003cInteger,Integer\u003e map = new HashMap\u003c\u003e(); // remainders\n        int count = 0;\n        map.put(0, 1);\n        int n = nums.length;\n        for(int i = 0; i \u003c n; i++) {\n            runningSum += nums[i];\n            int mod = runningSum % k;\n            if(mod \u003c 0)\n              mod += k;\n\n            if(map.containsKey(mod)) {\n                count += map.get(mod);\n            }\n            map.put(mod, map.getOrDefault(mod,0)+1);\n        }\n        return count;\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fsubarray-sums-divisible-by-k","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fsubarray-sums-divisible-by-k","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fsubarray-sums-divisible-by-k/lists"}