Block (Square)·Data Scientist·Technical Phone Screen
Jun 2026
Block (Square) data scientist technical screen, basically one long coding problem about graph traversal on a referral dataset. The question had a lot of moving parts and I'm still not sure I nailed the complexity justification.
- Given a directed referral graph loaded from a CSV (up to 1 million users, nullable referred_by, possible duplicates and cycles), implement a function that returns the referral chain from the earliest ancestor down to a given user. If a cycle is detected on the path, return both the cycle nodes in encounter order and the acyclic prefix leading into it.
- Compute root_ancestor and chain_depth for every user in O(n) time and O(n) space without recomputing paths from scratch for each user. Justify your complexity.
- Return the top 3 longest valid acyclic chains, with ties broken first by smaller root ancestor ID and then lexicographically by the full chain list.
- Describe and implement preprocessing for the CSV input: deduplicate rows keeping the earliest seen parent when conflicts exist, normalize null or empty referred_by values, handle referred_by values not present in the user list by treating them as external roots, and flag self-referrals.
- Write minimal unit tests covering an acyclic chain, a self-cycle, and a two-node cycle using the provided example rows.
“This was the core of the whole interview.”