FreeExam

Reviewable Data Utilities

Original Python coding interviews on auditable data changes, reconciliation, provenance, schema contracts, review scope, and deterministic exports.

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

  1. 1.Report changed fields with explicit presence flags

    Write field_diff(before, after) for string-key dicts of JSON values. For each added, removed or unequal field, emit [key,old_present,old_value,new_present,new_value], sorted by key. Use None for an absent value slot but preserve its False presence flag. Compare present values using Python equality. Omit unchanged fields and do not mutate either dict.

  2. 2.Reconcile repeated identifiers without losing counts

    Write multiset_delta(expected, observed), for lists of string ids. Return [id, expected_count, observed_count, observed_count-expected_count] for ids whose counts differ, sorted by id. Repeated rows matter; equal totals or equal sets do not prove agreement. Return [] when every identifier count matches.

  3. 3.Enforce a many-to-one join before emitting rows

    Write safe_left_join(facts, dimension). facts contains [fact_id,key] string pairs; dimension contains [string_key,JSON_value]. Return None if any dimension key repeats, even when values agree or no fact uses it. Otherwise return [fact_id,key,matched_bool,value] per fact in input order; use None when unmatched. A matched None value must retain matched=True. Do not mutate inputs.

  4. 4.Apply field edits only when all guards match

    Write guarded_edits(record, edits). Each edit is [key,expected_present,expected_value,new_present,new_value]; keys are unique strings. Check every guard against the original dict using Python equality when present. Ignore expected_value if expected_present=False. On any mismatch return None; otherwise return a new dict with requested sets/deletions. Ignore new_value for deletions. Do not mutate.

  5. 5.Choose a present field and retain its source index

    Write choose_sources(sources, fields). sources is an ordered list of dicts; fields is a unique ordered string list. For each field emit [field,source_index,value] from the first dict containing that key, including a None, False or 0 value. Emit [field,None,None] if absent everywhere. Preserve field order and do not mutate inputs.

  6. 6.Merge agreeing sources and expose every conflict

    Write merge_with_conflicts(sources), a list of string-key dicts of JSON values. For each field, compare all present values using Python equality. If all agree, retain that value in "merged"; otherwise omit it and emit [field, [[source_index,value],...]] in "conflicts". Conflict fields are sorted and observations retain source order. Missing fields do not vote. Return both outputs without mutation.

  7. 7.Return the first failed numeric review rule

    Write rule_trace(rows, rules). rows are dicts with unique string id and optional finite numeric/None fields. Each rule is [field,op,bound], with numeric bound and op "lt", "le" or "eq". A missing/None field fails. Evaluate rules in order and return {"accepted": ids,"rejected": [[id,first_failed_rule_index],...]}, preserving row order in both. Empty rules accept every row.

  8. 8.Locate repeated composite keys with row provenance

    Write key_collisions(rows, fields). rows are dicts; fields is an ordered unique string list, and every row contains those fields with string or None values. Group rows by the tuple of field values and return [key_as_list,row_indices] only for groups with at least two rows. Order groups by first row index and indices increasingly. Empty fields gives the same empty key to every row.

  9. 9.Take an ordered review sample across datasets

    Write review_sample(rows, limit). rows are [unique_string_id,string_dataset] pairs; limit is a nonnegative integer. Order datasets by first appearance. Repeatedly take the next unseen row from each nonempty dataset in that order, stopping after limit rows or exhaustion. Return selected ids. Keep each dataset's original row order and never repeat or wrap rows.

  10. 10.Construct half-open shard row ranges

    Write shard_offsets(shards). shards is an ordered list of [string_name,nonnegative_integer_row_count]. Return [name,start,end] per shard, with start equal to all earlier counts and end=start+count. Preserve zero-length shards and repeated names in their original positions. Return {"ranges": rows,"total": total_count}; ranges use half-open offsets.

  11. 11.Locate uncovered and multiply covered manifest spans

    Write audit_ranges(total, ranges). total is a nonnegative integer; ranges contains valid integer [start,end) pairs with 0<=start<end<=total, possibly repeated or unsorted. Return {"gaps": maximal zero-coverage intervals,"overlaps": maximal intervals covered at least twice}, each sorted by start. Merge adjacent intervals of the same reported kind even if their exact coverage counts differ.

  12. 12.Explain incompatible schema changes

    Write schema_breaks(before, after). Schemas map fields to [kind,nullable_bool], where kind is "int", "number" or "string". Report removed fields as "removed", newly added nonnullable fields as "required", incompatible kind changes as "type", and nullable-to-nonnullable changes as "nullability". Only int->number widening is compatible. Return [field,sorted reasons] for violations, sorted by field.

  13. 13.Redact named keys recursively without logging values

    Write redact_keys(value, keys, replacement). value is JSON data with string dict keys; keys lists exact key names to redact. Traverse dicts and lists. For a matching dict key replace its entire value with replacement, increment a count, and do not descend into it. Return {"value": new_data,"redacted": count}. Count matching keys even if already equal to replacement. Do not mutate inputs.

  14. 14.Compress only adjacent equal review decisions

    Write decision_runs(values), a list of JSON values compared with Python equality. Return [value,start,end] for maximal consecutive runs of equal values, where indices are half-open. Keep run order; equal values separated by another decision must remain separate. Return [] for an empty list and do not mutate values.

  15. 15.Trace lineage leaves and reject reachable cycles

    Write lineage_roots(graph, node). graph maps string nodes to dependency lists; an absent node or a node with no dependencies is a root. Return the sorted unique roots reachable from node, including node itself when a root. Return None if any reachable dependency cycle exists, even if another branch reaches a root. Ignore cycles not reachable from node. Do not mutate graph.

  16. 16.Preflight column lengths before assembling records

    Write zip_columns(columns, row_count). columns maps string names to lists of JSON values; row_count is a nonnegative integer. If any column length differs from row_count, return None. Otherwise return row_count new dict rows aligned by index. With no columns return that many empty dicts. Preserve explicit None values and do not mutate or share nested output values with inputs.

  17. 17.Audit internal sequence gaps and duplicates by stream

    Write sequence_ledger(rows), [string_stream,integer_sequence] pairs. For each stream, report {"gaps": inclusive missing [first,last] intervals strictly between its observed min and max, "duplicates": [sequence,count] for counts>1}. Sort streams, gaps and duplicate sequences. Repeated observations do not fill a different missing sequence. Empty input returns {}.

  18. 18.Apply each operation id once and reject changed retries

    Write apply_deltas(initial, operations). initial maps string accounts to integer balances; operations are [string_op_id,string_account,integer_delta]. Apply each op id once. An identical retry does nothing; a retry with a different account or delta returns None for the entire batch. Unknown accounts start at zero, including for zero deltas. Return new balances without mutating inputs.

  19. 19.Infer only unambiguous content-preserving file renames

    Write asset_changes(before, after), path->digest string dicts. Same-path unequal digests are "modified". Among removed and added paths only, pair a rename when a digest occurs exactly once on each side. Ambiguous matches stay removed/added. Return {"renamed": [[old,new],...],"removed": paths,"added": paths,"modified": paths}; sort each list lexically and renamed by old path.

  20. 20.Bound an ordered UTF-8 line export without skipping

    Write bounded_export(lines, budget). lines are strings without newlines; budget is a nonnegative integer byte limit. Keep the longest prefix whose UTF-8 encoding fits, counting one newline byte after every kept line, even an empty line. Stop at the first line exceeding budget; do not skip it. Return {"text": kept lines with trailing newlines,"bytes": used,"omitted": remaining line count}.

  21. 21.Serialize review records with a fixed JSON convention

    Write review_jsonl(rows), a list of JSON-compatible dicts with string keys and finite numbers. Encode each using json.dumps with sorted keys, separators=(",",":"), ensure_ascii=False and allow_nan=False. Preserve row and list order. Join records with one newline after every row; empty rows returns "". Do not normalize Unicode or reorder lists. Use this supplied Python convention.

  22. 22.Quarantine invalid JSON lines with exact line numbers

    Write parse_review_lines(text). Process physical lines with text.splitlines(), numbering from 1; ignore blank lines. Accept only JSON objects with finite numbers and no repeated object keys at any depth. Reject malformed JSON. Return {"rows": [[line_number,object],...],"invalid": rejected line numbers}, preserving line order. One invalid line must not discard valid neighbors.

  23. 23.Separate field presence from observed-value coverage

    Write field_coverage(rows, fields). rows are string-key dicts; fields is a unique ordered string list. Return [field,present_count,nonnull_count] in field order. present_count includes explicit None values. nonnull_count counts present values other than None, including False, 0, empty strings and empty containers. Missing keys count toward neither total. Do not mutate rows.

  24. 24.Convert known measurement units with row provenance

    Write convert_units(rows, factors). Each row is [string_name,finite_number_or_None,string_unit]; factors maps known units to positive finite multipliers. Unknown units are rejected even for None values. For known units multiply present values and preserve None. Return {"converted": [[index,name,value],...],"unknown": rejected indices}, in original order. Do not infer unit names or mutate inputs.

  25. 25.Expand a review scope through directed dependencies

    Write dependency_scope(selected, graph). selected lists string nodes; graph maps nodes to lists of required dependency nodes. Return the sorted unique union of selected nodes and all transitive dependencies. Nodes absent from graph still belong in the result. Follow edges only in the dependency direction. Repeated edges, duplicate selections and cycles must terminate without duplicate outputs.

  26. 26.Encode unambiguous string components with byte lengths

    Write composite_key(parts), a list of strings. Encode each part as decimal UTF-8 byte length, then ":", then the original string; concatenate all components. Include empty parts as "0:". Do not insert other separators, normalize Unicode or use character counts for lengths. Return "" for no parts. This is the supplied composite-key convention.

  27. 27.Find the smallest complete reviewer coverage set

    Write review_cover(owners, changed). owners maps reviewer strings to covered field lists; changed lists required fields. Return the smallest reviewer set covering all distinct changed fields. Return its names sorted; ties choose the lexicographically smallest name list. Empty changed returns []; impossible coverage returns None. Ignore fields outside changed. Inputs permit exhaustive search.

  28. 28.Recover original row positions after reordering

    Write row_permutation(before, after). Both lists contain unique string row ids. If their id sets differ, return None. Otherwise return the list of original before indices in after order. The output must describe a complete permutation, including index zero; return [] for two empty lists. Do not mutate either list.

  29. 29.Merge sorted partitions with stable source coordinates

    Write merge_partitions(parts), a list of nondecreasing integer lists. Emit [value,partition_index,row_index] for every item in global value order; equal values sort by partition index, then row index. Preserve all repeated items and empty partitions' original indices. Return [] if all partitions are empty. Do not mutate the input lists.

  30. 30.Apply a supplied age rule with explicit future rejection

    Write retention_decisions(rows, now, ttl, pinned). rows are [unique_string_id,integer_time]; now is integer and ttl is nonnegative integer. Reject future rows first as "future", even if pinned. Otherwise keep pinned ids or rows with now-time<=ttl; reject the rest as "expired". Return {"keep": ids,"reject": [[id,reason],...]}, preserving input order. pinned is a list of ids; do not mutate rows.