class Solution { public: int maxRemovals(string source, string pattern, vector& targetIndices) { int n = source.length(); int m = pattern.length(); vector dp(m + 1, numeric_limits::max()); dp[0] = 0;
4th solution class Solution { public: static const int MOD = 1e9 + 7; int numberOfWays(int n, int x, int y) { std::vector comb(x + 1, std::vector(x + 1, 0)); for (int i = 0; i
class Solution {
public:
int maxRemovals(string source, string pattern, vector& targetIndices) {
int n = source.length();
int m = pattern.length();
vector dp(m + 1, numeric_limits::max());
dp[0] = 0;
vector isTarget(n, false);
for (int idx : targetIndices) {
isTarget[idx] = true;
}
for (int i = 0; i < n; i++) {
for (int j = m; j > 0; j--) {
if (source[i] == pattern[j - 1] && dp[j - 1] != numeric_limits::max()) {
dp[j] = min(dp[j], dp[j - 1] + (isTarget[i] ? 1 : 0));
}
}
}
return targetIndices.size() - (dp[m] == numeric_limits::max() ? 0 : dp[m]);
}
};
4th solution
class Solution {
public:
static const int MOD = 1e9 + 7;
int numberOfWays(int n, int x, int y) {
std::vector comb(x + 1, std::vector(x + 1, 0));
for (int i = 0; i
4th one??
Code send pls