Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution provided doesn't even work for Marking the Event Timeline #18

Open
edisonfreire opened this issue Feb 27, 2025 · 0 comments
Open

Comments

@edisonfreire
Copy link

https://github.com/codepath/compsci_guides/wiki/Marking-the-Event-Timeline

This is a solution, I was able to come up with that actually worked using the BFS approach mentioned but the time complexity is kind of busted.

def mark_event_timeline(event: str, timeline: str):
    n = len(timeline)
    max_turns = n * 10
    t = '?' * n
    queue = deque([(t, [])])
    seen = set(t)
    while queue:
        curr_t, curr_path = queue.popleft()

        if len(curr_path) >= max_turns:
            continue

        if curr_t == timeline:
            return curr_path

        for i in range(0, n - len(event) + 1):
            if curr_t[i: i + len(event)] == event:
                continue  # no change
            new_t = curr_t[:i] + event + curr_t[i + len(event):]
            if new_t not in seen:
                queue.append((new_t, curr_path + [i]))
                seen.add(new_t)

    return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant