Leetcode Weekly contest 313 - Hard - Maximum Deletions on a String

preview_player
Показать описание
In this video we discuss the fourth problem of Leetcode Weekly contest 313

Рекомендации по теме
Комментарии
Автор

the dp[i]!=NULL in the inner loop is working because is shows with better splits before ans has been considered. So we ignored big answers.

proprogrammer
Автор

Hi Prakhar, Can you please let me know why this code is not working in C++

int deleteStr(string s, int index, vector<int> &dp){
if(index == s.size())
return 0;

if(dp[index] != -1)
return dp[index];
int res = 0;
bool found = false;
for(int i = index; i < index + (s.length() - index)/2 ; i++){
if(dp[i] != -1)
continue;

string a = s.substr(index, i + 1);
string b = s.substr(i + 1, i + 1 + (i - index + 1));
cout<<a<<" "<<b<<'\n';
if(a.compare(b) == 0){
found = true;
cout<<found;
res = max(res, 1+deleteStr(s, i+1, dp));
}
}
if(found == false)
return dp[index] = 1;
return dp[index] = res;
}
int deleteString(string s) {
vector<int> dp(s.size(), -1);
return deleteStr(s, 0, dp);
}

shivamgupta-niki
welcome to shbcf.ru