-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) Update categories with combinatoris algorithms
- Loading branch information
Showing
7 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var question = [ | ||
{ | ||
id: "count combis", | ||
category: "Combinatorics", | ||
placeHolderCpp: `int countCombinations(int n, int k) {\n // Base cases\n if (k == 0 || k == n) return 1;\n ...\n}\n`, | ||
placeHolderGo: `func countCombinations(n int, k int) int {\n // Base cases\n if k == 0 || k == n {\n return 1\n }\n ...\n}\n`, | ||
difficulty: "Easy", | ||
question: "Ways to choose k items from n items (no order)", | ||
answerImage: "", | ||
answerCpp: `int countCombinations(int n, int k) { | ||
if (k == 0 || k == n) return 1; | ||
return countCombinations(n - 1, k - 1) + countCombinations(n - 1, k); | ||
} | ||
`, | ||
answerGo: `func countCombinations(n int, k int) int { | ||
if k == 0 || k == n { | ||
return 1 | ||
} | ||
return countCombinations(n-1, k-1) + countCombinations(n-1, k) | ||
}` | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var question = [ | ||
{ | ||
id: "Permutations", | ||
category: "Combinatorics", | ||
placeHolderCpp: `int countPermutations(int n, int k) {\n int result = 1;\n for (int i = 0; i < k; ++i) {\n result *= (n - i);\n }\n ...\n}\n`, | ||
placeHolderGo: `func countPermutations(n int, k int) int {\n result := 1\n for i := 0; i < k; i++ {\n result *= (n - i)\n }\n ...\n}\n`, | ||
difficulty: "Medium", | ||
question: "Ways to arrange k items from a set of n-length permutations.", | ||
answerImage: "", | ||
answerCpp: `int countPermutations(int n, int k) { | ||
int result = 1;\n for (int i = 0; i < k; ++i) { | ||
result *= (n - i); | ||
} | ||
return result; | ||
}`, | ||
answerGo: `func countPermutations(n int, k int) int { | ||
result := 1 | ||
for i := 0; i < k; i++ { | ||
result *= (n - i) | ||
} | ||
return result\n}\n` | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var question = [ | ||
{ | ||
id: "subsets", | ||
category: "Combinatorics", | ||
placeHolderCpp: `void generateSubsets(const vector<int>& nums, int index, vector<int>& current, vector<vector<int>>& result) {\n // Recursive function to generate all subsets of a set\n ...\n}\n`, | ||
placeHolderGo: `func generateSubsets(nums []int, index int, current []int, result *[][]int) {\n // Recursive function to generate all subsets of a set\n ...\n}\n`, | ||
difficulty: "Hard", | ||
question: "Generate all subsets of a given set of integers.", | ||
answerImage: "", | ||
answerCpp: `void generateSubsets(const vector<int>& nums, int index, vector<int>& current, vector<vector<int>>& result) { | ||
if (index == nums.size()) { | ||
result.push_back(current); | ||
return; | ||
} | ||
generateSubsets(nums, index + 1, current, result); | ||
current.push_back(nums[index]); | ||
generateSubsets(nums, index + 1, current, result); | ||
current.pop_back(); | ||
}`, | ||
answerGo: `func generateSubsets(nums []int, index int, current []int, result *[][]int) { | ||
if index == len(nums) { | ||
subset := make([]int, len(current)) | ||
copy(subset, current) | ||
*result = append(*result, subset) | ||
return | ||
} | ||
generateSubsets(nums, index+1, current, result) | ||
current = append(current, nums[index]) | ||
generateSubsets(nums, index+1, current, result) | ||
current = current[:len(current)-1] | ||
}` | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var question = [ | ||
{ | ||
id: "unique paths", | ||
category: "Combinatorics", | ||
placeHolderCpp: `int uniquePaths(int m, int n) {\n // Number of unique paths in an m x n grid\n int paths = ...\n}\n`, | ||
placeHolderGo: `func uniquePaths(m int, n int) int {\n // Number of unique paths in an m x n grid\n paths := ...\n}\n`, | ||
difficulty: "Hard", | ||
question: "top-left to the bottom-right unique paths", | ||
answerImage: "", | ||
answerCpp: `int uniquePaths(int m, int n) { | ||
int paths[m][n]; | ||
for (int i = 0; i < m; i++) paths[i][0] = 1; | ||
for (int j = 0; j < n; j++) paths[0][j] = 1; | ||
for (int i = 1; i < m; i++) { | ||
for (int j = 1; j < n; j++) { | ||
paths[i][j] = paths[i - 1][j] + paths[i][j - 1]; | ||
} | ||
} | ||
return paths[m - 1][n - 1]; | ||
}`, | ||
answerGo: `func uniquePaths(m int, n int) int { | ||
paths := make([][]int, m) | ||
for i := range paths { | ||
paths[i] = make([]int, n) | ||
} | ||
for i := 0; i < m; i++ { | ||
paths[i][0] = 1 | ||
} | ||
for j := 0; j < n; j++ { | ||
paths[0][j] = 1 | ||
} | ||
for i := 1; i < m; i++ { | ||
for j := 1; j < n; j++ { | ||
paths[i][j] = paths[i-1][j] + paths[i][j-1] | ||
} | ||
} | ||
return paths[m-1][n-1] | ||
}` | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters