← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a classic dynamic programming problem. Nothing too exotic but you really do need to have the DP formulation clean in your head before you walk in.

Questions Asked (1)

Q1

Given a knapsack with a fixed weight capacity and a set of items each having a weight and a value, find the combination of items that maximizes total value without exceeding the capacity.

Algorithms & Data Structures
Author's notes

Classic 0/1 knapsack.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., item weights/values, capacity, whether items can be taken fractionally). Then explain that this is the classic 0/1 knapsack problem, which can be solved optimally using dynamic programming in O(n*W) time and space. Walk through the DP formulation, recurrence, and how to reconstruct the selected items.

Pro tip: Mention that while the DP solution is optimal for small capacities, for large capacities you might consider approximation algorithms or meet-in-the-middle for small n. Also, discuss how Uber might use this in real-world scenarios like resource allocation or delivery packing.

1. Clarify the problem

Ask if items can be taken fractionally (0/1 vs fractional knapsack) and confirm the goal is to maximize value without exceeding capacity. Also check constraints on n and capacity.

2. Choose the right algorithm

For 0/1 knapsack, dynamic programming is optimal. For fractional, a greedy approach by value/weight ratio works. Explain why DP is needed for 0/1.

3. Define the DP state and recurrence

Let dp[i][w] be the max value using first i items with capacity w. Recurrence: dp[i][w] = max(dp[i-1][w], dp[i-1][w-w_i] + v_i) if w_i <= w.

4. Optimize space and reconstruct solution

Use a 1D array to reduce space to O(W). To reconstruct items, either keep a 2D table or store decisions. Discuss trade-offs.

5. Analyze complexity and edge cases

Time O(nW), space O(W) with 1D DP. Handle edge cases: zero capacity, items heavier than capacity, negative values (if allowed).

Key Points to Mention

  • 0/1 knapsack vs fractional knapsack: DP vs greedy
  • DP state definition and recurrence relation
  • Time and space complexity: O(nW) time, O(W) space with optimization
  • How to reconstruct the selected items (e.g., backtracking or storing choices)
  • Edge cases: capacity 0, item weight > capacity, empty item list
  • Potential follow-ups: large capacity (approximation, meet-in-the-middle), unbounded knapsack

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