{"id":22513959,"url":"https://github.com/emahtab/combinations","last_synced_at":"2026-01-07T21:05:27.967Z","repository":{"id":79525376,"uuid":"273889906","full_name":"eMahtab/combinations","owner":"eMahtab","description":"Combinations","archived":false,"fork":false,"pushed_at":"2020-06-21T11:25:40.000Z","size":1,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:26:13.900Z","etag":null,"topics":["combinations","leetcode","problem-solving"],"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":"2020-06-21T11:24:11.000Z","updated_at":"2020-06-21T11:28:21.000Z","dependencies_parsed_at":"2023-05-10T17:16:04.873Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/combinations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcombinations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcombinations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcombinations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcombinations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/combinations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952375,"owners_count":20699476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["combinations","leetcode","problem-solving"],"created_at":"2024-12-07T03:15:17.204Z","updated_at":"2026-01-07T21:05:22.685Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Combinations\n## https://leetcode.com/problems/combinations\n\nGiven two integers n and k, return all possible combinations of k numbers out of **1 ... n.**\n```\nExample:\n\nInput: n = 4, k = 2\nOutput:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]\n```\n# Implementation : Recursive \n```java\nclass Solution {\n    public List\u003cList\u003cInteger\u003e\u003e combine(int n, int k) {\n        List\u003cList\u003cInteger\u003e\u003e result = new ArrayList\u003c\u003e();\n\t \n\t\tif (n \u003c= 0 || n \u003c k)\n\t\t\treturn result;\n\t \n\t\tList\u003cInteger\u003e item = new ArrayList\u003cInteger\u003e();\n\t\tdfs(n, k, 1, item, result); // because it need to begin from 1\n\t \n\t\treturn result;\n    }\n     \n\tprivate void dfs(int n, int k, int start, List\u003cInteger\u003e item, List\u003cList\u003cInteger\u003e\u003e res) {\n\t\tif (item.size() == k) {\n\t\t\tres.add(new ArrayList\u003cInteger\u003e(item));\n\t\t\treturn;\n\t\t}\n\t \n\t\tfor (int i = start; i \u003c= n; i++) {\n\t\t\titem.add(i);\n\t\t\tdfs(n, k, i + 1, item, res);\n\t\t\titem.remove(item.size() - 1); // removing the last added element\n\t\t}\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcombinations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fcombinations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcombinations/lists"}