FreeExam

Lineage and Dependency Algorithms

Original Python data engineer interviews on pinned provenance, dependency cycles, rebuild witnesses, source explanations, exact path support and bounded recovery planning.

These problems are original practice. They are not questions from a named employer or a live hiring loop.

  1. 1.Normalize known lineage without hiding invalid edge evidence

    Write normalize_lineage(nodes, edges). nodes unique strings; edges [input,output] strings. Keep only edges whose endpoints are both declared. Return {"nodes":sorted_nodes,"edges":unique_known_edges_sorted_lexicographically,"invalid":input_edge_indices_with_any_unknown_endpoint}. Self edges are valid evidence here; duplicate invalid rows retain all indices. No mutation.

  2. 2.Find all upstream tables without including a cyclic self

    Write upstream_tables(edges, table). Directed edges [input,output] have string IDs. Return sorted distinct nodes that can reach table by one or more edges, excluding table itself even if a cycle returns to it. Parallel edges add no extra node. A table absent from all edges has no upstream nodes. No mutation.

  3. 3.Retain changed origins through propagation barriers

    Write changed_origins(edges, changed, barriers). All IDs strings, edges input->output. Each distinct changed node reaches itself and downstream nodes; a reached barrier is included but propagation stops there, including when the origin itself is a barrier. Return [node,sorted_origin_ids] sorted by node for all reached nodes. Cycles and repeated edges are allowed. No mutation.

  4. 4.Separate simultaneous rebuild waves from blocked remainders

    Write rebuild_layers(nodes, edges, done). nodes unique strings; edges input->output with known endpoints; done subset of nodes. Repeatedly emit all unfinished nodes whose parents are done or emitted earlier, sorted as one wave, then mark the whole wave complete. Stop if none ready. Return {"layers":waves,"blocked":sorted_unemitted}. Cycles may block themselves and downstream nodes. No mutation.

  5. 5.Identify actual cycle members rather than all blocked tables

    Write cycle_tables(nodes, edges). nodes unique strings, <=40; directed input->output edges have known endpoints. Return sorted nodes lying on a directed cycle of at least one edge. A self edge is a cycle. A descendant blocked behind a cycle is not a member unless a path returns to it. Parallel edges do not create a cycle by themselves. No mutation.

  6. 6.Condense lineage with deterministic component identities

    Write condense_lineage(nodes, edges). <=30 unique string nodes; known directed endpoints. Group nodes that can reach each other, allowing zero-step self reach. Sort each group, then groups by their smallest member; component IDs are these list indices. Return {"groups":groups,"edges":sorted_unique_component_pairs}, excluding within-group edges. Include isolated nodes. No mutation.

  7. 7.Keep constant columns external leaves and cycles distinct

    Write column_sources(bindings, outputs). bindings maps string column ID to parent-ID list; absent binding is an external leaf, empty list a constant with no source. Per output expand all parents recursively. Return [output,sorted_distinct_leaf_ids] in output order, but source field None if ANY reachable cycle prevents complete expansion, even with other leaf branches. No mutation.

  8. 8.Evaluate ALL and ANY support without erasing unknown inputs

    Write gate_values(bindings, available, outputs). bindings maps ID to ["all"/"any",parents], a DAG. Unbound leaves use available bool/None, missing means None. ALL: False if any False, else None if any None, else True. ANY: True if any True, else None if any None, else False. Empty ALL=True, ANY=False. Return [output,value] in request order. No mutation.

  9. 9.Choose a shortest full-path lexicographic lineage witness

    Write provenance_path(edges, source, target). IDs strings; directed edges input->output, cycles/duplicates allowed. Return a node-ID path with fewest edges, then lexicographically smallest entire path, or None if unreachable. source==target returns [source], even absent from edges. Do not choose ties using only the final predecessor. No mutation.

  10. 10.Stop rebuild requirements at materialized checkpoints

    Write rebuild_closure(edges, targets, materialized). String IDs; edges input->output, cycles allowed. Start from targets and recursively require parents unless the current node is materialized. Cached nodes themselves and ancestors reached through that branch need no execution. Return sorted distinct required uncached nodes, including uncached targets. No mutation.

  11. 11.Audit exact producer revisions for every consumer dependency

    Write parent_revision_gaps(actual, requirements). actual: string table->integer revision/None; absent/None is unsupported. requirements [consumer,parent,wanted_integer_revision], unique consumer/parent pairs. Return [consumer,[[parent,wanted,actual_or_None],...]] for mismatches only, sorted by consumer then parent. Higher revisions still mismatch pinned lower ones. No mutation.

  12. 12.Resolve exact table and revision lineage identities

    Write version_closure(records, requested). records [string_table,integer_revision,parent_pairs], unique table/revision pairs; requested lists such pairs. Follow exact parents, including missing records; cycles allowed. Return {"required":sorted_distinct_pairs,"missing":sorted_unregistered_pairs}. Revisions of one table remain distinct nodes. Empty parent lists are complete roots. No mutation.

  13. 13.Compare source attribution across lineage edits

    Write attribution_delta(old, new, sources, outputs). Directed edge lists and string ID lists; repeats ignored, cycles allowed. Source supports output iff reachable, including a zero-edge self path. Return [output,added_sources,removed_sources] only where source support differs, sorted by output; source lists sorted. Removing one edge is harmless if another path preserves attribution. No mutation.

  14. 14.Remove only direct DAG edges with alternative support paths

    Write reduce_dependencies(edges). String input->output edges form a DAG; duplicate pairs ignored. Return sorted unique edges that have no alternative path from input to output after removing that direct pair. Redundancy decisions use the original deduplicated graph. Retain necessary cover edges; no mutation.

  15. 15.Count parallel witnesses and zero-edge path support

    Write path_multiplicities(edges, source, outputs). DAG with <=12 string IDs, <=24 edge occurrences. Each edge occurrence is a distinct transformation witness, so parallel rows multiply path counts. Return [output,path_count] in output order, including duplicates. source has one zero-edge path; disconnected outputs have zero. Count exact integers without modulo. No mutation.

  16. 16.Find tables present on every supported provenance path

    Write mandatory_tables(edges, source, target). String-ID DAG; duplicate edges ignored. Return sorted node IDs present on EVERY source-to-target path, including endpoints, or None if target unreachable. source==target has only the zero-edge path and returns [source]. Nodes appearing on some alternative paths are not mandatory. No mutation.

  17. 17.Preserve tied critical producers in completion traces

    Write critical_trace(durations, edges). durations maps all node IDs to integer duration>=0; known input->output edges form a DAG, duplicates ignored. All roots can start at 0. Finish(node)=duration+max(parent finishes), empty max 0. Return [node,finish,sorted_critical_parents] sorted by node; critical parents attain that maximum, empty for roots. Zero-finish parents still count. No mutation.

  18. 18.Propagate latest starts through all downstream consumers

    Write deadline_windows(durations, edges, deadline). Nonnegative integer durations for all known nodes; input->output DAG edges, duplicates ignored; deadline integer. Every sink must finish by deadline. Latest finish(node)=minimum latest start of its children, or deadline for sinks; latest start=finish-duration. Return [node,start,finish] sorted; retain negative starts. No mutation.

  19. 19.Reject invalid run events without changing dependency state

    Write audit_runs(nodes, edges, events). Unique string nodes, known input->output edges; events [node,"start"/"finish"]. Initially pending. start needs pending then all parents done; finish needs running. Invalid events leave state unchanged; reasons first "unknown", "order", then "blocked". Return {"states":[[node,state]] sorted,"rejected":[[event_index,reason]]}. Done cannot restart. No mutation.

  20. 20.Find inclusion-minimal source sets for ALL and ANY lineage

    Write minimal_sources(bindings, target). DAG bindings: ID->["all"/"any",parents]; absent IDs are leaves. <=8 leaves, <=16 bindings. A leaf needs itself; ALL every parent, ANY at least one. Return inclusion-minimal supporting leaf sets as sorted lists, ordered by (size,list). Empty ALL has one empty proof [[]]; empty ANY has no proof []. Repeated parents add no requirement. No mutation.

  21. 21.Propagate provenance tags to a lineage fixed point

    Write origin_tags(tags, edges). tags maps every node ID to string-tag list, duplicates allowed; known input->output edges, cycles allowed. Each node retains its own tags and receives all tags from every reachable upstream node. Return [node,sorted_distinct_tags] sorted by node, including empty lists. Iterate to a fixed point; one edge pass may be insufficient. No mutation.

  22. 22.Count maximum edge-disjoint indexed support paths

    Write edge_disjoint(nodes, edges, source, target). <=8 unique string nodes, <=20 directed known-endpoint edges; source and target distinct declared nodes. Each edge occurrence has capacity 1, including parallel duplicates. Return the maximum number of source-to-target paths sharing no edge occurrence. Intermediate nodes may be shared. Cycles allowed. No mutation.

  23. 23.Find a minimum-cost interior isolation cut for lineage

    Write isolation_cut(edges, source, target, costs). Directed string IDs, cycles allowed; source!=target. costs maps <=10 removable interior nodes to positive integer cost; endpoints excluded, other nodes unremovable. Return sorted removed IDs minimizing (total_cost,count,ID_list) that destroy all source->target paths, or None if impossible. Already unreachable returns []. No mutation.

  24. 24.Count valid rebuild orders including isolated tables

    Write rebuild_order_count(nodes, edges). <=10 unique string nodes; known input->output edges, duplicates ignored; cycles allowed. Return the exact number of permutations of ALL nodes placing every input before its output. A self edge or directed cycle gives 0. Empty node list has one empty schedule. Isolated nodes can appear anywhere. No mutation.

  25. 25.Group weak lineage regions including isolated tables

    Write weak_components(nodes, edges). Unique string nodes, known directed endpoints. Group nodes connected when each edge may be traversed in either direction; include isolated nodes. Return sorted members per group, groups sorted by smallest member. Duplicate and self edges do not change groups. This is weak connectivity, not mutual directed reachability. No mutation.

  26. 26.Rank path scores exactly before hop and witness ties

    Write scored_path(edges, source, target). DAG with <=8 string IDs and <=20 edges [input,output,n,d], integers 0<=n<=d<=100, d>0. Score is the exact product of n/d. Return {"score":[reduced_numerator,denominator],"path":IDs} maximizing score, then minimizing (hops,path_ID_list), or None if unreachable. Self zero-edge score is 1. No mutation.

  27. 27.Find a cheapest allowed lineage walk under a hop cap

    Write bounded_route(edges, source, target, forbidden, max_hops). edges [string_input,string_output,integer_cost>=0], cycles allowed; forbidden IDs, max_hops integer 0..8. Among walks using <=max_hops and no forbidden node, minimize (total_cost,hops,path_ID_list). Return {"cost":integer,"path":IDs} or None. Self zero-edge walk allowed unless forbidden. No mutation.

  28. 28.Find a maximum incomparable rebuild frontier

    Write independent_frontier(nodes, edges). <=10 unique string nodes; known input->output DAG edges. A frontier subset has no directed path between any two distinct members in either direction. Return a largest frontier as sorted IDs, breaking size ties by lexicographically smallest ID list. Do not equate this maximum with the largest simultaneous topological layer. No mutation.

  29. 29.Optimize materializations against shared rebuild work

    Write checkpoint_plan(work_costs, edges, targets, cache_costs, budget). Known string-node DAG; work costs integers>=0; <=10 cache costs positive ints; budget>=0. Chosen caches stop upstream traversal before execution. Rebuild union of uncached targets/parents. Minimize (rebuild_cost,cache_cost,sorted_cached_IDs). Return {"cached":IDs,"work":sorted_required,"cost":rebuild_cost}. No mutation.

  30. 30.Cover bad outputs while respecting good-output evidence

    Write hypothesis_cover(edges, costs, bad, good). Directed string IDs, cycles allowed; <=10 candidate costs positive integers. Candidates support reachable outputs, including themselves. Cover every bad output while reaching NO good output. Return sorted IDs minimizing (total_cost,count,ID_list), or None if impossible; empty bad returns []. Hypotheses are not proven faults. No mutation.