I am solving this question from hackerearth…
The logic which i have followed…
Here i am using map to do memoization…
Now for each index i am iterating…
case - 1–if the size of string is 0 … then i have 2 option whether to include present character or not…
case-2-- if size of string is 1 then i will include only that character which is euqal to 0th character of present string…
case-3-- if size of string is 2 then we can include that character if it is one greater than 1st chharacter of present string…
case - 4-- if size of string is 3… then it is same as case-2…
case - 5… if size of string is 4 and it satisfy the condition then return 1 else return 0…
this my submision…
https://www.hackerearth.com/submission/51662951/
Please see this.
Thanks…