FreeExam

Operational Diagnosis Tools

Original Python coding interviews on telemetry integrity, error-budget calculations, trace evidence, queue diagnostics, rollout state, and explicit health decisions.

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

  1. 1.Separate observed counter resets from negative work

    Write counter_rates(samples), [integer_time,nonnegative_integer_count] rows with strictly increasing times. For each adjacent pair use delta=new-old if new>=old, otherwise delta=new under the supplied reset-to-zero rule. Return [old_time,new_time,delta,delta/elapsed] rows. Fewer than two samples returns []. Zero is an observed count. Do not extrapolate beyond the supplied endpoints.

  2. 2.Keep stale gauge values distinct from current zero

    Write fresh_gauges(samples, queries, ttl). samples is [integer_time,finite_value_or_None] rows, unsorted; queries lists integer times; ttl>=0 is integer. Per query choose greatest sample time<=query, ties last arrival. Return [sample_time,value,stale_bool]; stale if age>ttl, replacing stale values with None. No eligible sample gives [None,None,True]. Fresh None remains stale=False. Keep order.

  3. 3.Recover disjoint counts from cumulative histogram buckets

    Write bucket_counts(cumulative), a list of integer cumulative bucket counts in increasing boundary order, including any final overflow bucket. Return disjoint counts by adjacent subtraction, using previous count 0 for the first bucket. Return None if any count is negative or cumulative counts decrease. Equal consecutive counts represent an empty bucket. Empty input returns [].

  4. 4.Aggregate bucket counts before locating a quantile bracket

    Write quantile_bracket(bounds, histograms, q) for nonnegative measurements. bounds lists increasing positive upper bounds; valid cumulative-count rows have len(bounds)+1 entries, last overflow. Sum rows; rank=ceil(q*total), with exact-decimal q in (0,1]. Return [previous_bound_or_0,first_bound_reaching_rank], upper None for overflow. Zero total returns None. Do not interpolate.

  5. 5.Report fractional allowed errors and normalized burn

    Write error_budget(good, total, target). Counts are integers with 0<=good<=total; target is a supplied decimal fraction in [0,1). Let bad=total-good and allowed=total*(1-target), without flooring. Return {"bad":bad,"allowed":allowed,"remaining":allowed-bad,"burn":(bad/total)/(1-target) or None when total=0}. Interpret target as an exact decimal; report numeric outputs without rounding.

  6. 6.Require supported burn breaches in both supplied windows

    Write dual_burn(short, long, target, threshold, min_requests). Each window is None or [bad,total] integers, 0<=bad<=total. target is in [0,1), threshold>=0, min_requests is positive integer. Return True only if both windows exist, both totals>=min_requests and both (bad/total)/(1-target)>=threshold. Interpret decimal inputs exactly. This returns a decision only, without sending an alert.

  7. 7.Combine same-time queue deltas before checking underflow

    Write queue_balance(events, initial). events is [integer_time,nonnegative_arrivals,nonnegative_completions] rows with nondecreasing times; initial>=0 is integer. Combine all events at the same timestamp, then apply arrivals-completions. Return [time,depth] per distinct timestamp. Return None if any combined depth is negative. Empty events returns []; do not invent an initial-time row.

  8. 8.Apply a supplied queue-area estimator with explicit units

    Write queue_estimate(area, duration, completed). area is nonnegative finite queue-depth*time area, duration is positive finite observed time, and completed is a nonnegative integer completion count. Return {"mean_depth":area/duration,"throughput":completed/duration,"wait":area/completed or None when completed=0}. Use the supplied formula without rounding.

  9. 9.Rank only arrived unfinished work by age

    Write pending_ages(arrivals, finished, now). arrivals is [unique_string_id,integer_arrival_time] rows; finished lists ids already completed by integer now. Return [id,now-arrival] for arrived ids not finished, sorted by age decreasing then id. Exclude future arrivals, ignore unknown finished ids, and retain age zero. Do not mutate inputs.

  10. 10.Subtract the union of direct child spans only

    Write exclusive_times(spans), [unique_string_id,parent_id_or_None,integer_start,integer_end] rows forming a valid forest, start<=end. Each child is contained in its parent. Per span return duration minus the union length of its direct children. Children may overlap; do not subtract overlaps twice or subtract grandchildren again. Return id->exclusive_time without mutation. Empty input returns {}.

  11. 11.Separate rooted spans from missing or cyclic ancestry

    Write span_roots(parents), a dict mapping string span ids to a parent id or None. For each id follow its parent chain. If it reaches a declared None-parent root, put id->root_id in "valid"; if it reaches an unknown id or repeats an id, put the starting id in sorted "invalid". Descendants of a broken chain are invalid too. Empty-string ids are valid strings. Return both outputs without mutation.

  12. 12.Find the earliest divergent deployment manifest

    Write first_drift(expected, snapshots). expected maps component strings to revision strings; snapshots is [integer_time,manifest_dict] rows, possibly unsorted. Compare each whole manifest with expected: missing, extra or unequal revisions are changes. Return {"at":time,"changes":sorted component names} for the earliest divergent snapshot, ties by original arrival. Otherwise return None.

  13. 13.Reject a rollout transition at its first invalid event

    Write rollout_state(events), initially "idle". Allowed transitions: idle/start->canary; canary/pass->rolling; canary/fail->rollback; rolling/finish->done; rolling/fail->rollback; rollback/reset->idle; done/reset->idle. Return {"state":last valid state,"invalid":first invalid zero-based event index or None}. Stop at that first invalid event, including unknown event names. Empty events retains idle.

  14. 14.Keep missing unhealthy and wrong-version replicas visible

    Write rollout_coverage(expected, observations, target). expected lists unique string ids; observations is [id,version_string,healthy_bool] rows, last arrival per id wins. Ignore ids outside expected. Return expected-order id lists: "ready" for healthy target version, "wrong" for observed other version, "unhealthy" for observed False, "missing" for unobserved ids. wrong and unhealthy may overlap.

  15. 15.Clip and union outage reports before computing availability

    Write outage_summary(reports, window). reports is unsorted integer [start,end) outage intervals with start<end; window is [left,right] with left<right. Clip reports to the half-open window, discard empty intersections, and merge overlapping or touching outages. Return {"intervals":merged sorted spans,"downtime":union length,"availability":1-downtime/(right-left)}. Count overlap once.

  16. 16.Retain alarm state between entry and exit thresholds

    Write hysteresis_states(values, low, high), finite numbers with low<high; values may also contain None. Initially off. While off, value>=high turns on; while on, value<=low turns off; other finite values retain state. None always retains state. Return the Boolean state after each observation. Equality belongs to the entry/exit comparisons, not the middle band.

  17. 17.Require a sustained breach with bounded observation gaps

    Write sustained_breaches(samples, threshold, hold, gap). samples is [integer_time,finite_value] rows with strictly increasing times; hold/gap are nonnegative integers. A run requires value>threshold and gaps<=gap. A lower/equal value or larger gap breaks it. Emit the first sample time reaching elapsed run duration>=hold, once per run. hold=0 can emit at the run's first sample. Return times.

  18. 18.Suppress repeated alert keys without extending the cooldown

    Write alert_cooldown(alerts, window). alerts is [id,string_key,integer_time] rows with nondecreasing times; window is positive integer. Emit a key's first alert, then emit again only if time>=last_emitted_time+window. Suppressed alerts do not update that time. Return {"emit":ids,"suppress":ids}, preserving input order in each list. Keys have independent cooldowns.

  19. 19.Apply a declared upstream-alert inhibition rule transitively

    Write inhibited_alerts(active, dependencies). active lists service strings; dependencies is an acyclic service->upstream_services dict. Absent nodes have no upstreams. Inhibit an active service if any other active service is reachable upstream, even through inactive nodes. Return sorted unique "page" and "inhibited" service lists. Evaluate only this supplied rule.

  20. 20.Measure series merges after dropping selected labels

    Write label_cardinality(rows, drop). rows are string->string label dicts; drop lists label names. A series is identified by all sorted key/value pairs. Return {"before":distinct original series,"after":distinct reduced series,"largest_merge":maximum number of distinct originals mapping to one reduced series, or 0 if no rows}. Duplicate observations do not add series.

  21. 21.Match expected and observed scrapes one to one

    Write match_scrapes(expected, observed, tolerance), sorted unique integer time lists and integer tolerance>=0. Compare earliest remaining times: match if absolute difference<=tolerance; otherwise mark the earlier observed time extra or earlier expected time missing. Report leftovers. Return {"matched":[expected,observed] rows,"missing":times,"extra":times}. Use earliest feasible pairs.

  22. 22.Distinguish a draining queue from nonpositive net service

    Write drain_estimate(backlog, arrivals, service). Inputs are nonnegative integers; rates are units per minute. Under the supplied constant-rate model, return whole minutes ceil(backlog/(service-arrivals)) if backlog>0 and service>arrivals. Return None for positive backlog with service<=arrivals. A zero backlog returns 0 regardless of rates. Do not round a positive fractional time down.

  23. 23.Weight saturated gauge evidence by observed duration

    Write saturation_time(samples, start, end, threshold, ttl). samples is [integer_time,finite_value] rows with strictly increasing times; start<end and ttl>0 are integers. Hold each sample until the next sample or its time+ttl, whichever first. Clip to [start,end). Return {"known":covered duration,"saturated":duration with value>threshold,"fraction":saturated/known or None}. Omit unsupported time.

  24. 24.Check four-timestamp offset and delay arithmetic

    Write clock_exchanges(rows), integer [a=local_send,b=remote_receive,c=remote_send,d=local_receive] timestamps. Per row compute offset=((b-a)+(c-d))/2 and delay=(d-a)-(c-b). Return {"offset":...,"delay":...}, or None for that row if local elapsed d-a, remote elapsed c-b or computed delay is negative. Preserve row order. Only perform arithmetic on supplied timestamps.

  25. 25.Require enough fresh healthy reports from expected voters

    Write health_quorum(voters, reports, required, now, ttl). voters lists unique ids; reports is unsorted [id,integer_time,healthy_bool]. Use each voter's latest time<=now, ties last arrival. Missing or age>ttl is unknown; otherwise classify healthy/unhealthy. Return these three id lists in voter order plus "ready": healthy_count>=required. required/ttl>=0 and now are integers. Ignore unlisted ids.

  26. 26.Find a shortest declared failure path to an affected target

    Write failure_path(graph, failed, target). graph maps string nodes to downstream lists; failed lists source nodes. Return a path from any failed node to target using the fewest edges, ties by lexicographically smallest entire path. If target is failed return [target]; if unreachable return None. Repeated edges, duplicate sources and cycles must terminate. Missing keys have no outgoing edges.

  27. 27.Fit an unscaled median deviation baseline from history only

    Write mad_flags(history, current, cutoff). history is nonempty finite numbers; current is finite numbers; cutoff>=0 is finite. Fit center=median(history), mad=median(abs(x-center) for history). Return {"median":center,"mad":mad,"flags": abs(current-center)>cutoff*mad}. If mad=0, flag values unequal to center. Even medians average their middle two values. Do not refit with current observations.

  28. 28.Preserve overlap and support in lagged correlation

    Write lag_correlations(a, b, lags). a/b are equally long finite numeric lists; lags lists integers in desired output order. At lag k pair a[t] with b[t+k] only where both indices exist. Return [k,pair_count,r], with r=sum(dx*dy)/sqrt(sum(dx^2)*sum(dy^2)) using overlap-centered values. r is None for fewer than two pairs or zero variance. Do not zero-pad or infer causation.

  29. 29.Count observed attempts without filling missing indices

    Write retry_amplification(events), [string_request,nonnegative_integer_attempt] rows. Count unique request ids and distinct (request,attempt) pairs; ignore duplicate observations. Return {"requests":request_count,"attempts":pair_count,"amplification":attempts/requests or None if empty,"retried":sorted ids with more than one observed attempt}. Sparse indices do not imply missing attempts occurred.

  30. 30.Find visible checkpoint events with unmet dependencies

    Write cut_violations(cut, dependencies). cut maps partition strings to nonnegative committed offsets; an unknown partition has offset -1. dependencies is [partition,event_offset,required_partition,required_offset] rows; offsets are nonnegative integers. Report a row only if its event is included by cut but its required event is not. Return sorted unique violations. Ignore events outside the cut.