String constructible from short list of words? AtCoder ABC049C - Daydream
It seems to be fine. What are the failing cases' inputs? Following your link I only see 3 cases which should indeed work.

However, I see there's a limitation of time and memory usage at the beginning, and that S max length is 100000. Your code might for example exceed maximum recursion depth.
I think a simpler solution would be to use regex. For example (and I added a long sample):

import re
import random

regexPattern = "^(dream(er)?|eraser?)*$"
sampleList = [
    "erasedream",
    "dreameraser",
    "dreamerer"]

# just add a looooooong sample
longSample = ""
mandatoryWords = ["dream", "dreamer", "erase", "eraser"]
while True:
    addWord = mandatoryWords[random.randint(0, 3)]

    if len(longSample) + len(addWord) &gt; 100000:
        break
    else:
        longSample += addWord

sampleList.append(longSample)

for sample in sampleList:
    match = re.fullmatch(regexPattern, sample)

    if match != None:
        print("YES")
    else:
        print("NO")


outputs

YES
YES
NO
YES