Skip to content

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

Open
@edisonfreire

Description

@edisonfreire

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 []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions