You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 []
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: