← Upstart Interview Insights

Upstart·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Interviewed for a software engineering role at Upstart and got a graph/grid problem that looked deceptively simple on the surface. The core of it was modeling block removal as a topological sort, which I thought I knew cold but fumbled a bit explaining the dependency direction.

Questions Asked (1)

Q1

Given a grid of blocks where a block can only be removed if no block to its right in the same row is still present, model this as a dependency graph and return any block that is currently removable. Then walk through how you'd extend this to simulate the full removal sequence.

Algorithms & Data StructuresSystem Design
Author's notes

I started by thinking about it left-to-right and almost got the dependency direction backwards.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each block as a node in a dependency graph where an edge points from a block to the block immediately to its right in the same row, since a block depends on that right neighbor being removed first. To find a removable block, identify a node with no outgoing edges (i.e., the rightmost present block in any row). For the full removal sequence, repeatedly remove such nodes and update dependencies, which is essentially a topological sort on the reversed graph.

Pro tip: Clarify that the dependency graph is a forest of disjoint paths (one per row), so the problem reduces to maintaining the rightmost present block per row; this simplifies the solution and avoids overcomplicating with general graph algorithms.

1. Model the dependencies

Create a graph where each block is a node, and add a directed edge from block (r, c) to block (r, c+1) if both exist, representing that (r, c) depends on (r, c+1) being removed first.

2. Identify removable blocks

A block is removable if it has no outgoing edges (i.e., no block to its right in the same row). Initially, these are the rightmost blocks in each row.

3. Simulate removal

To simulate the full sequence, repeatedly pick a removable block, remove it, and update the graph: the block immediately to its left (if any) may become removable. Use a queue or stack to manage candidates.

4. Handle dynamic updates

After removing a block, check its left neighbor; if it exists and has no right neighbor, add it to the set of removable blocks. Continue until no blocks remain.

5. Analyze complexity

Each block is removed once, and each removal involves O(1) updates, so the total time is O(N) where N is the number of blocks, assuming we can access neighbors efficiently.

Key Points to Mention

  • Dependency graph representation: nodes as blocks, edges as 'depends on' relationships.
  • Removable condition: no outgoing edges (rightmost in row).
  • Topological sort perspective: removal order is a topological ordering of the reversed graph.
  • Efficient simulation using a queue of currently removable blocks.
  • Graph structure is a set of disjoint paths (one per row), simplifying the problem.
  • Time and space complexity: O(N) time and O(N) space for the graph or O(rows) if optimized.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.