<jupyter_start><jupyter_text>https://www.educative.io/courses/grokking-the-coding-interview/gxJrM9goEMr<jupyter_code>def is_scheduling_possible(tasks, prerequisites):
    """this technique uses BFS"""
    if tasks == 0:
        return True
    child_connects = {i:0 for i in range(tasks)}
    graph = {i:[] for i in range(tasks)}
    for left,right in prerequisites:
        graph[left].append(right)
        child_connects[right] += 1
    res = []
    current_tasks = deque([k for (k,v) in child_connects.items() if v == 0])
    while current_tasks:
        task = current_tasks.popleft()
        res.append(task)
        for child in graph[task]:
            child_connects[child] -= 1
            if child_connects[child] == 0:
                current_tasks.append(child)
    return len(res) == tasks


print("Is scheduling possible: " +
    str(is_scheduling_possible(3, [[0, 1], [1, 2]]))) # True
print("Is scheduling possible: " +
    str(is_scheduling_possible(3, [[0, 1], [1, 2], [2, 0]]))) # False
print("Is scheduling possible: " +
    str(is_scheduling_possible(6, [[0, 4], [1, 4], [3, 2], [1, 3]]))) # True<jupyter_output>Is scheduling possible: True
Is scheduling possible: False
Is scheduling possible: True<jupyter_text>https://www.educative.io/courses/grokking-the-coding-interview/BnnArPGKolJ<jupyter_code>def find_order(tasks, prerequisites):
    if not tasks:
        return []
    res = []
    graph = {i:[] for i in range(tasks)}
    in_degree = {i:0 for i in range(tasks)}
    for left, right in prerequisites:
        graph[left].append(right)
        in_degree[right] += 1
    
    current_tasks = deque([k for (k,v) in in_degree.items() if v == 0])
    while current_tasks:
        task = current_tasks.popleft()
        res.append(task)
        for child in graph[task]:
            in_degree[child] -= 1
            if in_degree[child] == 0:
                current_tasks.append(child)
    return res if len(res) == tasks else []


print("Is scheduling possible: " + str(find_order(3, [[0, 1], [1, 2]])))
print("Is scheduling possible: " +
    str(find_order(3, [[0, 1], [1, 2], [2, 0]])))
print("Is scheduling possible: " +
    str(find_order(6, [[2, 5], [0, 5], [0, 4], [1, 4], [3, 2], [1, 3]])))<jupyter_output>Is scheduling possible: [0, 1, 2]
Is scheduling possible: []
Is scheduling possible: [0, 1, 4, 3, 2, 5]
{'fraction_non_alphanumeric': 0.15699658703071673, 'fraction_numerical': 0.02858361774744027, 'mean_word_length': 3.2100538599640935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '100909', 'license': 'MIT', 'n_tokens_mistral': 879, 'n_tokens_neox': 812, 'n_words': 211, 'path': 'ed_graphs.ipynb', 'repo_name': 'devkosal/code_challenges', 'size': '2344'}