← Airbnb Interview Insights

Airbnb·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Apr 2026

Summary

Airbnb software engineer interview with a graph optimization problem. Pretty involved algorithmically and I spent more time than I'd like to admit just making sure I understood what the scoring function was actually asking.

Questions Asked (1)

Q1

You're given a weighted directed acyclic graph where each node has a score and each edge has a time cost. Starting from a fixed source node with score zero, find the path to any node whose name starts with an underscore that maximizes total node scores minus total edge costs. Return the maximum value and optionally the path itself.

Algorithms & Data Structures
Author's notes

The objective function tripped me up at first because you're mixing node weights and edge costs in the same sum, which feels a little unusual.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a longest path problem in a DAG with node weights and edge costs, solvable in O(V+E) using dynamic programming in topological order. Define DP[v] as the maximum net score to reach v, initialize DP[source]=0, and for each node in topological order, relax outgoing edges: DP[to] = max(DP[to], DP[from] + score[to] - cost). Finally, scan all nodes whose name starts with '_' and return the maximum DP value.

Pro tip: Clarify edge cases upfront: what if no underscore node is reachable? What if multiple paths tie? Also mention that if the graph weren't a DAG, the problem would be NP-hard, so the DAG property is crucial.

1. Clarify problem and constraints

Confirm that the graph is a DAG, node scores can be negative, edge costs are non-negative, and the source is fixed. Ask whether the path must end at an underscore node or if any underscore node is acceptable.

2. Define DP state and recurrence

Let dp[v] be the maximum net score to reach node v from the source. Initialize dp[source] = 0 and dp[v] = -infinity for others. For each edge (u, v) with cost c, update dp[v] = max(dp[v], dp[u] + score[v] - c).

3. Process nodes in topological order

Compute a topological ordering of the DAG (e.g., via DFS or Kahn's algorithm). Iterate through nodes in that order, relaxing all outgoing edges to ensure each node's dp is finalized before it is used.

4. Find optimal underscore node and reconstruct path

After DP, scan all nodes with names starting with '_' and pick the one with maximum dp value. If path reconstruction is required, store parent pointers during relaxation and backtrack from the chosen node.

5. Analyze complexity and edge cases

State that time and space are O(V+E). Handle unreachable underscore nodes by returning -infinity or a sentinel, and discuss negative scores and zero-cost edges.

Key Points to Mention

  • Topological sort is essential to process nodes in dependency order, enabling O(V+E) DP.
  • DP state definition: maximum net score to reach each node, incorporating both node scores and edge costs.
  • Relaxation formula: dp[v] = max(dp[v], dp[u] + score[v] - edge_cost(u,v)).
  • Path reconstruction using parent pointers if the path itself is needed.
  • Handling unreachable underscore nodes and negative scores.
  • Contrast with general graphs: longest path is NP-hard, but DAG makes it tractable.

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