From d743284636136593cf76acdc11fd35c6f3a48e55 Mon Sep 17 00:00:00 2001 From: "Dr.Dread" <135847306+DrDread746@users.noreply.github.com> Date: Wed, 29 Oct 2025 09:48:13 +0530 Subject: [PATCH 1/3] 3297. Count Substrings That Can Be Rearranged to Contain a String I --- ...an Be Rearranged to Contain a String I.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 3297. Count Substrings That Can Be Rearranged to Contain a String I.cpp diff --git a/3297. Count Substrings That Can Be Rearranged to Contain a String I.cpp b/3297. Count Substrings That Can Be Rearranged to Contain a String I.cpp new file mode 100644 index 0000000..42bcd5e --- /dev/null +++ b/3297. Count Substrings That Can Be Rearranged to Contain a String I.cpp @@ -0,0 +1,26 @@ +class Solution { +public: + long long validSubstringCount(string word1, string word2) { + int count = 0; + long long ans = 0; + int l = 0, r = 0; + vector map2(27, 0), map1(27, 0); + for (int i = 0; i < word2.size(); i++) { + map2[word2[i] - 'a']++; + } + while (r < word1.size()) { + map1[word1[r] - 'a']++; + if (map1[word1[r] - 'a'] == map2[word1[r] - 'a']) + count += map2[word1[r] - 'a']; + while (count == word2.size()) { + ans += (word1.size() - r); + map1[word1[l] - 'a']--; + if (map1[word1[l] - 'a'] < map2[word1[l] - 'a']) + count -= map2[word1[l] - 'a']; + l++; + } + r++; + } + return ans; + } +}; From 90556cd95125738edd9b7a9dd3ed4f2af4589f05 Mon Sep 17 00:00:00 2001 From: "Dr.Dread" <135847306+DrDread746@users.noreply.github.com> Date: Wed, 29 Oct 2025 09:57:36 +0530 Subject: [PATCH 2/3] 3298. Count Substrings That Can Be Rearranged to Contain a String II --- ...n Be Rearranged to Contain a String II.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 3298. Count Substrings That Can Be Rearranged to Contain a String II.cpp diff --git a/3298. Count Substrings That Can Be Rearranged to Contain a String II.cpp b/3298. Count Substrings That Can Be Rearranged to Contain a String II.cpp new file mode 100644 index 0000000..42bcd5e --- /dev/null +++ b/3298. Count Substrings That Can Be Rearranged to Contain a String II.cpp @@ -0,0 +1,26 @@ +class Solution { +public: + long long validSubstringCount(string word1, string word2) { + int count = 0; + long long ans = 0; + int l = 0, r = 0; + vector map2(27, 0), map1(27, 0); + for (int i = 0; i < word2.size(); i++) { + map2[word2[i] - 'a']++; + } + while (r < word1.size()) { + map1[word1[r] - 'a']++; + if (map1[word1[r] - 'a'] == map2[word1[r] - 'a']) + count += map2[word1[r] - 'a']; + while (count == word2.size()) { + ans += (word1.size() - r); + map1[word1[l] - 'a']--; + if (map1[word1[l] - 'a'] < map2[word1[l] - 'a']) + count -= map2[word1[l] - 'a']; + l++; + } + r++; + } + return ans; + } +}; From ccc18dea36609d85911ef13aa37fccc60c6cb00f Mon Sep 17 00:00:00 2001 From: "Dr.Dread" <135847306+DrDread746@users.noreply.github.com> Date: Wed, 29 Oct 2025 10:44:10 +0530 Subject: [PATCH 3/3] 740. Delete and Earn --- 740. Delete and Earn.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 740. Delete and Earn.cpp diff --git a/740. Delete and Earn.cpp b/740. Delete and Earn.cpp new file mode 100644 index 0000000..9c10023 --- /dev/null +++ b/740. Delete and Earn.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + int deleteAndEarn(vector& nums) { + int m = 10001; + int n = nums.size(); + int maxVal = 0; + vector f(m, 0); + vector dp(m + 1, 0); + + for (int i = 0; i < n; i++) { + f[nums[i]]++; + maxVal = max(maxVal, nums[i]); + } + + dp[1] = f[1]; + for (int i = 2; i <= maxVal; i++) { + dp[i] = max(dp[i - 1], dp[i - 2] + f[i] * i); + } + + return dp[maxVal]; + } +};