← 返回博客列表
Google

Google SWE Intern Interview: Car Rental Capacity Planning + Binary Tree Island Count (Two Rounds, Smooth Pass)

2026-03-18

3.18 Google SWE intern, two rounds. Both interviewers were friendly and the pace was comfortable. Full recap below.

Google Logo


Interview Overview

Item Details
Company Google
Role SWE Intern
Rounds 2 technical rounds
Overall Smooth, interviewers friendly
Date 2026-03-18

Round 1

Self-Introduction & Project Questions

Started with a self-introduction, then the interviewer asked about project experience. Conversation flowed naturally.

Coding: Car Rental Capacity Planning

Problem

Given all rental orders from last year, each order containing a pickup time and a return time, find:

  1. The minimum number of cars needed to satisfy all orders
  2. One valid car assignment plan (an example is sufficient)

Approach

Core Idea: Difference Array / Sweep Line

Split each order into two events:

Sort all events by time and sweep left to right, tracking the current number of cars in use. The peak value equals the minimum number of cars required.

Boundary note: If a pickup and a return happen at the same time, process the return (−1) first, then the pickup (+1) — this allows reusing the just-returned car.

Car Assignment Plan

Maintain a pool of idle cars:

This yields one valid assignment example.

Code Template

def min_cars(orders):
    events = []
    for start, end in orders:
        events.append((start, 1))   # pickup +1
        events.append((end, -1))    # return -1

    # Same time: process return (-1) before pickup (+1) to reuse cars
    events.sort(key=lambda x: (x[0], x[1]))

    cur = 0
    peak = 0
    for _, delta in events:
        cur += delta
        peak = max(peak, cur)
    return peak


def assign_cars(orders):
    """Return car ID assigned to each order (example plan)"""
    events = []
    for i, (start, end) in enumerate(orders):
        events.append((start, 1, i))
        events.append((end, -1, i))
    events.sort(key=lambda x: (x[0], x[1]))

    pool = []       # idle car IDs
    next_car = 0    # next new car ID
    assignment = {} # order_idx -> car_id
    active = {}     # order_idx -> car_id (in-progress orders)

    for time, delta, idx in events:
        if delta == -1:          # return
            car = active.pop(idx)
            pool.append(car)
        else:                    # pickup
            if pool:
                car = pool.pop()
            else:
                car = next_car
                next_car += 1
            active[idx] = car
            assignment[idx] = car

    return assignment

Complexity

Follow-up: Check if Two Time Intervals Overlap

Given intervals [a, b] and [c, d], determine if they overlap.

Conclusion: Two intervals are non-overlapping if and only if b <= c or d <= a (touching endpoints count as non-overlapping). Negate for the overlap condition:

def is_overlap(a, b, c, d):
    # Overlap: neither completely left nor completely right
    return not (b <= c or d <= a)

Round 2

Behavioral Questions

The interviewer was a friendly white engineer. Two BQ questions:

  1. Tell me about a time you collaborated with a team
  2. How do you handle disagreements with a colleague?

Coding: Binary Tree Island Count

Problem

Given a binary tree where each node has value 0 or 1.

An "island of 1s" is a maximal connected region of nodes with value 1 (connected via parent-child edges, not broken by any 0 node).

Given the root of the tree, return the number of islands.

Approach

Recursively traverse the tree:

Key: a new island is counted whenever we encounter a 1 node whose parent is 0 (or when the root itself is 1).

Code Template

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


def count_islands(root):
    """Return the number of 1-islands in the binary tree"""
    def dfs(node, parent_is_one):
        if node is None:
            return 0
        count = 0
        if node.val == 1 and not parent_is_one:
            # Start of a new island
            count += 1
        count += dfs(node.left, node.val == 1)
        count += dfs(node.right, node.val == 1)
        return count

    return dfs(root, False)

Complexity

Follow-up: If the Tree Were a Graph, How to Avoid Double-Counting?

When the structure becomes a general graph, a node may be reachable via multiple paths, causing DFS/BFS to revisit the same node and count islands multiple times.

Solution: mark visited nodes

def count_islands_graph(graph, values):
    """
    graph: {node_id: [neighbor_ids]}
    values: {node_id: 0 or 1}
    """
    visited = set()

    def dfs(node, parent_is_one):
        if node in visited:
            return 0
        visited.add(node)
        count = 0
        if values[node] == 1 and not parent_is_one:
            count += 1
        for neighbor in graph[node]:
            count += dfs(neighbor, values[node] == 1)
        return count

    total = 0
    for node in graph:
        if node not in visited:
            total += dfs(node, False)
    return total

Key points:


Side-by-Side Comparison

Problem Core Technique Time Space
Car Rental Capacity Sweep line + pool assignment O(n log n) O(n)
Binary Tree Islands DFS + parent state propagation O(n) O(h)
Graph Islands (follow-up) DFS + visited deduplication O(V+E) O(V)

Common Mistakes

Problem Mistake Correct Approach
Car Rental Enumerate every time point Only process event points, sweep line O(n log n)
Car Rental Process pickup before return at same time Return first, then pickup — reuse the car
Tree Islands Count 0 nodes as part of islands 0 nodes are separators, not part of any island
Graph Islands No visited set, double-counting Always use a visited set

Google Interview Strategy

On-site Pacing

  1. Restate the problem before coding to confirm understanding
  2. Talk through your approach and wait for the interviewer's nod before writing code
  3. Proactively address follow-ups: ask "What if the input is larger / the structure becomes a graph?"
  4. After coding, trace through an example and verify edge cases (empty tree, all-0, all-1)

Related LeetCode Practice

# Problem Covers
56 Merge Intervals Interval sweep line
253 Meeting Rooms II Difference array / min resources
200 Number of Islands Island count DFS
547 Number of Provinces Graph connected components
695 Max Area of Island Island DFS variant

🚀 Need Google VO Assistance?

oavoservice provides stable, long-term real-time OA/VO support for Google, Amazon, TikTok, Uber, Bloomberg, Microsoft and more — both domestic and overseas interviews covered. High question-bank coverage.

Add WeChat: Coding0201

What you get:

📱 WeChat: Coding0201 | 💬 Telegram: @OAVOProxy | 📧 [email protected]


Contact

Email: [email protected]
Telegram: @OAVOProxy