From bdefe7467e9ac103e36ab76c84c15797b99421a0 Mon Sep 17 00:00:00 2001 From: SUJAY GIJRE Date: Sat, 7 Feb 2026 15:50:43 -0500 Subject: [PATCH 1/2] Create subset.cpp --- subset.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 subset.cpp diff --git a/subset.cpp b/subset.cpp new file mode 100644 index 00000000..90e95937 --- /dev/null +++ b/subset.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + vector> answer; + void backtrack(vector temp, vector& nums, int index) { + answer.push_back(temp); + + if (index == nums.size()) { + return; + } + + for (int i=index;i> subsets(vector& nums) { + vector temp; + backtrack(temp, nums, 0); + return answer; + } +}; From 3e9b5f1e7378f7aef6a04d127084ad6e3bbba37a Mon Sep 17 00:00:00 2001 From: SUJAY GIJRE Date: Sat, 7 Feb 2026 15:52:03 -0500 Subject: [PATCH 2/2] Create palindrome_partitioning.cpp --- palindrome_partitioning.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 palindrome_partitioning.cpp diff --git a/palindrome_partitioning.cpp b/palindrome_partitioning.cpp new file mode 100644 index 00000000..45314a8b --- /dev/null +++ b/palindrome_partitioning.cpp @@ -0,0 +1,35 @@ +class Solution { +public: + vector> answer; + void backtrack(vector temp, int start, string s) { + + if (start >= s.length()) { + answer.push_back(temp); + } + + auto isPalindrome = [=] (string substring) -> bool { + int start = 0; + int end = substring.length()-1; + while (start < end) { + if (substring[start++] != substring[end--]) { + return false; + } + } + return true; + }; + + for (int i=start;i creates substring from index+1 of size length + if (isPalindrome(str)) { + temp.push_back(str); + backtrack(temp, i+1, s); + temp.pop_back(); + } + } + } + vector> partition(string s) { + vector temp; + backtrack(temp, 0, s); + return answer; + } +};