Disaster Recovery
Reported by candidates from Headlands's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're looking at a Headlands OA from March 2026 that sounds like a graph connectivity problem dressed up in disaster recovery language. The real task: parse a corrupted log, group commits by shared file-identifier pairs (union-find territory), detect if any file maps to multiple identifiers (which makes input ambiguous), then answer range queries on the valid repository. It's a constraint-satisfaction and graph problem wrapped in log recovery. StealthCoder can spot the union-find hook and the ambiguity check when you're live.
The problem
A global log describes commits applied across multiple repositories after a corrupted migration. Each valid log line begins with id timestamp followed by zero or more file-path / opaque-identifier pairs. Two commits belong to the same repository when they can be connected through at least one matching (filePath, opaqueIdentifier) pair. If the same connected component would force one file path to have two different opaque identifiers, the input is ambiguous. Malformed log lines must be discarded. They do not themselves make the input ambiguous. After all log lines are processed, answer repository queries of the form "startTimestamp endTimestamp filePath opaqueIdentifier". For each query, return the commit IDs for the matching repository, filtered to the inclusive timestamp range, sorted by increasing timestamp and then increasing commit ID. Each response line should preserve the original trailing space behavior from the prompt. If the input is ambiguous anywhere, return a single-line result containing AMBIGUOUS INPUT!. Function Description Complete processRepositoryQueries. processRepositoryQueries has the following parameters: Returns: String[] of query responses, or ["AMBIGUOUS INPUT!"] when the logs are ambiguous. Commits 0 and 1 belong to the same repository because they share bar b. Commit 2 is isolated. Each query filters the connected component by timestamp and preserves the required trailing space. The three commits would be connected through shared files, but the connected component assigns two different opaque identifiers to foo. That makes the entire input ambiguous, so queries are ignored and only AMBIGUOUS INPUT! is returned.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern here is union-find with a twist. Each commit is a node. When two commits share a (filePath, opaqueIdentifier) pair, they belong to the same repository, so union them. The catch: after unioning, you must validate that no file path in the same connected component has two different opaque identifiers. If it does, return AMBIGUOUS INPUT immediately and stop processing queries. Malformed lines are skipped silently. Once the graph is valid, store commits by component, then for each query, find the component containing the queried (filePath, opaqueIdentifier), filter commits by timestamp range, and sort by timestamp then commit ID. The ambiguity check is the trap most candidates miss. StealthCoder will flag it during the OA.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Disaster Recovery cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderYou've seen the question.
Make sure you actually pass Headlands's OA.
Headlands reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Disaster Recovery FAQ
What makes the input ambiguous?+
If the same file path appears in one connected component with two different opaque identifiers. Example: commit A has (foo, b), commit B has (foo, c), and they're connected through other shared pairs. This is ambiguous because foo cannot belong to two different identifiers. The moment you detect this, return AMBIGUOUS INPUT and ignore all queries.
How do I handle malformed log lines?+
Discard them silently. They don't contribute to ambiguity. A malformed line might have missing timestamp, invalid pairs, or format errors. Parse defensively: if a line doesn't have id and timestamp, skip it. Don't crash, don't flag ambiguity for malformed input.
How do I group commits into repositories?+
Use union-find. Iterate through log lines. For each line, extract id, timestamp, and all (filePath, opaqueIdentifier) pairs. For each pair, union the commit with all other commits that share that exact pair. After all lines are processed, check for ambiguity. If valid, group commits by their root in the union-find structure.
What do queries ask for?+
Each query specifies startTimestamp, endTimestamp, filePath, and opaqueIdentifier. Find the repository (connected component) that contains that (filePath, opaqueIdentifier) pair. Return commit IDs from that component whose timestamps fall in the range, sorted by timestamp then commit ID. Preserve trailing spaces from the original prompt if specified.
Is this problem still hard if I miss the ambiguity check?+
Yes. If you skip ambiguity detection, you'll return wrong results for ambiguous inputs. The problem explicitly tests it. Build the union-find, then validate: for each component, iterate all commits and their pairs. If the same file path has two different opaque identifiers in the component, it's ambiguous. Check this before answering any queries.