diff --git a/README.md b/README.md index 5c55af5..e46505c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,8 @@ | Longest Valid Parentheses | [LeetCode](https://leetcode.com/problems/longest-valid-parentheses/) | [YouTube](https://www.youtube.com/watch?v=VdQuwtEd10M) | [Java](./codes/java/LongestValidParentheses.java) | | Rotate Image | [LeetCode](https://leetcode.com/problems/rotate-image/) | [YouTube](https://www.youtube.com/watch?v=Y72QeX0Efxw) | [Java](./codes/java/RotateImage.java) | | Substring with concatenation of all words | [LeetCode](https://leetcode.com/problems/substring-with-concatenation-of-all-words/) | [YouTube](https://www.youtube.com/watch?v=_MGzsJ0F8lE) | [Java](./codes/java/SubstringWithConcatenationOfAllWords.java) | -|Largest rectangular sub-matrix having sum divisible by k| [GFG](https://www.geeksforgeeks.org/largest-rectangular-sub-matrix-sum-divisible-k/) | [YouTube](https://www.youtube.com/watch?v=_MGzsJ0F8lE) | [Python](./codes/python/largest_rectangular_sub_matrix_sum_divisbl_by_k) | +|Largest rectangular sub-matrix having sum divisible by k| [GFG](https://www.geeksforgeeks.org/largest-rectangular-sub-matrix-sum-divisible-k/) | [YouTube](https://www.youtube.com/watch?v=_MGzsJ0F8lE) | [Python](./codes/python/largest_rectangular_sub_matrix_sum_divisbl_by_k) +|Combination Sum III |[LeetCode](https://leetcode.com/problems/combination-sum-iii/) |[Youtube](https://youtu.be/rP_K3WJnRR4?si=W1RUODPlWwOSvsnV) |[C++](./codes/cpp/combination_sum_iii.cpp) diff --git a/codes/cpp/combination_sum_iii.cpp b/codes/cpp/combination_sum_iii.cpp new file mode 100644 index 0000000..35f8572 --- /dev/null +++ b/codes/cpp/combination_sum_iii.cpp @@ -0,0 +1,41 @@ +#include +#include +using namespace std; + +void findProperSubSet(int k,int n,vector>&ans,vector&partAns,int l){ + if(k==0&&n<0) + return; + if(k==0&&n==0){ + ans.push_back(partAns); + return; + } + if(k==0&&n>0) + return; + for(int i=l;i<=9;i++){ + partAns.push_back(i); + findProperSubSet(k-1,n-i,ans,partAns,i+1); + partAns.pop_back(); + } + + } +vector> combinationSum3(int k, int n) { + vector>ans; + vectorpartAns; + findProperSubSet(k,n,ans,partAns,1); + return ans; +} +int main() +{ + int k,n; + cin>>k; + cin>>n; + vector>ans=combinationSum3(k,n); + for(int i=0;i