Forward from: TCS HackQuest Season 9 Solutions
String Obsession
C++
TCS CodeVita Zone 2
100% Correct Code ✅
https://telegram.me/+_hn3cBQVbGliYTI9
#include
#include
#include
#include
https://telegram.me/+_hn3cBQVbGliYTI9
using namespace std;
int dp(string& s, vector& v, unordered_map& memo) {
if (memo.count(s)) return memo[s];
// @PLACEMENTLELO
int placementlelo = 0;
https://telegram.me/+_hn3cBQVbGliYTI9
for (auto& x : v) {
size_t pos = s.find(x);
// @PLACEMENTLELO
if (pos != string::npos) {
string new_string = s.substr(0, pos) + s.substr(pos + x.size());
placementlelo = max(placementlelo, 1 + dp(new_string, v, memo));
}
}
// @PLACEMENTLELO
return memo[s] = placementlelo;
}
int main() {
int n;
cin >> n;
// @PLACEMENTLELO
vector substrings(n);
for (int i = 0; i < n; ++i) {
cin >> substrings[i];
}
https://telegram.me/+_hn3cBQVbGliYTI9
string mainString;
cin >> mainString;
// @PLACEMENTLELO
unordered_map memo;
cout
C++
TCS CodeVita Zone 2
100% Correct Code ✅
https://telegram.me/+_hn3cBQVbGliYTI9
#include
#include
#include
#include
https://telegram.me/+_hn3cBQVbGliYTI9
using namespace std;
int dp(string& s, vector& v, unordered_map& memo) {
if (memo.count(s)) return memo[s];
// @PLACEMENTLELO
int placementlelo = 0;
https://telegram.me/+_hn3cBQVbGliYTI9
for (auto& x : v) {
size_t pos = s.find(x);
// @PLACEMENTLELO
if (pos != string::npos) {
string new_string = s.substr(0, pos) + s.substr(pos + x.size());
placementlelo = max(placementlelo, 1 + dp(new_string, v, memo));
}
}
// @PLACEMENTLELO
return memo[s] = placementlelo;
}
int main() {
int n;
cin >> n;
// @PLACEMENTLELO
vector substrings(n);
for (int i = 0; i < n; ++i) {
cin >> substrings[i];
}
https://telegram.me/+_hn3cBQVbGliYTI9
string mainString;
cin >> mainString;
// @PLACEMENTLELO
unordered_map memo;
cout