From 922e74705a0153e87bf1e33853cc50d111a7998a Mon Sep 17 00:00:00 2001 From: chayan das Date: Wed, 2 Jul 2025 15:13:57 +0530 Subject: [PATCH] Create 3333. Find the Original Typed String II --- 3333. Find the Original Typed String II | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 3333. Find the Original Typed String II diff --git a/3333. Find the Original Typed String II b/3333. Find the Original Typed String II new file mode 100644 index 0000000..a08489d --- /dev/null +++ b/3333. Find the Original Typed String II @@ -0,0 +1,44 @@ +class Solution { + static constexpr int MOD = 1'000'000'007; +public: + int possibleStringCount(string word, int k) { + vector groups; + for(int i = 0, n = word.size(); i < n; ) { + int j = i+1; + while(j (int)groups.size()) { + vector dp(k), newdp(k); + dp[0] = 1; + for(int idx = 0; idx < m; idx++) { + int len = groups[idx]; + fill(newdp.begin(), newdp.end(), 0); + + long long window = 0; + for(int j = 1; j < k; j++) { + window = (window + dp[j-1]) % MOD; + if(j - 1 - len >= 0) + window = (window - dp[j - 1 - len] + MOD) % MOD; + newdp[j] = window; + } + dp.swap(newdp); + } + + long long invalid = 0; + for(int j = 1; j < k; j++) + invalid = (invalid + dp[j]) % MOD; + + return int((total - invalid + MOD) % MOD); + } + // If minimum intended length <= #groups, we don't exclude anything + return int(total); + } +};