โ† ่ฟ”ๅ›žๅšๅฎขๅˆ—่กจ
Google

๐Ÿšจ Google 2026 Interview: Island Evacuation Plane Scheduling โ€” Why 90% Failed This 'Simple' Greedy Problem?

2026-01-19

Manufacturing Anxiety: Breaking the Illusion

Recently, this Google interview question has been circulating in job hunting groups everywhere.

Many people's first reaction: "Isn't this just sorting + simulation? Easy!"

Dead wrong.

If you just write a brute force simulation, congratulations โ€” the interviewer will smile and hit you with three Followups, then you'll get rejected.

Our oavoservice team obtained this question immediately and discovered it's packed with Greedy Algorithm, Binary Search, and Edge Case challenges.


Question Breakdown: Demonstrating Expertise

๐Ÿ” Original Problem

You're on a remote island that needs evacuation due to pending flooding. The government is sending planes tomorrow to get some people out. If you miss the last plane you'd have to take a slower boat the following day which you don't want. Given the plane schedule and the schedule of all your fellow islanders, What is the latest you could get to the airport tomorrow and still get evacuated?

๐Ÿ“ Problem Analysis

You're stranded on a remote island about to be flooded.

The government is sending multiple planes tomorrow to evacuate some islanders.

If you miss all flights, you'll have to take a slow boat the next day (you definitely don't want that).

Given:

Rule: First come, first served, limited seats

Question: What's the latest you can arrive at the airport and still guarantee a seat?


Deep Dive: Building Trust

๐Ÿง  Problem Essence Analysis

This problem appears to be a "scheduling problem," but actually tests:

Test Point Specific Content
Greedy Thinking How to allocate passengers to flights?
Binary Search How to efficiently find the critical time point?
Edge Case Handling Full flights, no flights, time conflicts
Complexity Optimization From O(nยฒ) brute force to O(n log n) optimization

๐Ÿ“Š Input/Output Format

Input:
- flights: List[(departure_time, capacity)]  # Flight list: (departure time, seats)
- arrivals: List[int]  # Other islanders' airport arrival times

Output:
- int: Latest arrival time that guarantees boarding
- Return -1 if impossible to board any flight

๐ŸŽฏ Example Analysis

Example 1:

flights = [(100, 2), (200, 1)]  # Flight 1: departs at 100, 2 seats; Flight 2: departs at 200, 1 seat
arrivals = [50, 80]  # Two islanders arrive at times 50 and 80

Output: 199

Explanation:
- Flight 1 (departs 100, 2 seats): Islanders arriving before 100 can board
  - Islander A(50), Islander B(80) both board, filling 2 seats
- Flight 2 (departs 200, 1 seat): People arriving before 200 can board
  - No one else competing for this flight, you just need to arrive by 199

So the answer is 199

Example 2:

flights = [(100, 1)]  # Only one flight, 1 seat
arrivals = [50]  # One islander arrives at time 50

Output: 49

Explanation:
- The only flight departs at 100, with just 1 seat
- Islander A arrives at 50; if you arrive after 50, the seat is taken
- So you must arrive at 49 or earlier

Example 3:

flights = [(100, 1)]
arrivals = [50, 60]  # Two islanders

Output: -1

Explanation:
- Only 1 seat, but 2 islanders arrive before you can
- No matter when you arrive, there's no seat left
- Return -1

Solution: Core Algorithm

Approach 1: Brute Force Simulation O(n ร— m ร— log m)

The most intuitive idea: enumerate your arrival time and simulate the entire boarding process.

def latest_arrival_brute_force(flights, arrivals):
    """
    Brute force: enumerate all possible arrival times
    flights: List[(departure_time, capacity)]
    arrivals: List[int] - other islanders' arrival times
    """
    # Collect all possible time points
    all_times = set(arrivals)
    for dep, _ in flights:
        all_times.add(dep - 1)  # moment before departure
        all_times.add(dep)
    
    all_times = sorted(all_times, reverse=True)  # enumerate from late to early
    
    for my_time in all_times:
        if can_board(flights, arrivals, my_time):
            return my_time
    
    return -1

But this is too slow! Let's optimize...

Approach 2: Correct Greedy Strategy

Core Insight:

  1. Sort flights by departure time
  2. Sort passengers by arrival time
  3. Each passenger greedily chooses the "earliest available flight"
  4. Binary search for your latest arrival time

Approach 3: Final Correct Version

def latest_arrival_time(flights, arrivals):
    """
    Google Interview Question: Island Evacuation
    
    Args:
        flights: List[Tuple[int, int]] - (departure_time, capacity)
        arrivals: List[int] - other islanders' arrival times
    
    Returns:
        int: Latest arrival time guaranteeing evacuation, -1 if impossible
    """
    if not flights:
        return -1
    
    # Sort by departure time
    flights = sorted(flights, key=lambda x: x[0])
    n_flights = len(flights)
    
    # Total seats
    total_seats = sum(cap for _, cap in flights)
    
    # If not enough seats for everyone (including you)
    if total_seats <= len(arrivals):
        return -1
    
    def simulate(my_time):
        """
        Simulate whether you can board if arriving at my_time
        Returns True if successful evacuation
        """
        # Everyone sorted by arrival time
        everyone = sorted(arrivals + [my_time])
        
        # Remaining seats per flight
        seats = [cap for _, cap in flights]
        
        # Pointer to current flight being considered
        flight_ptr = 0
        
        for person_arrival in everyone:
            # Find first flight with departure_time > arrival_time
            while flight_ptr < n_flights and flights[flight_ptr][0] <= person_arrival:
                flight_ptr += 1
            
            # From flight_ptr, find a flight with available seats
            boarded = False
            for i in range(flight_ptr, n_flights):
                if seats[i] > 0:
                    seats[i] -= 1
                    boarded = True
                    break
            
            if not boarded and person_arrival == my_time:
                return False
        
        return True
    
    # Binary search for latest arrival time
    # Earliest possible is 0, latest is one moment before last flight departs
    lo, hi = 0, flights[-1][0] - 1
    result = -1
    
    while lo <= hi:
        mid = (lo + hi) // 2
        if simulate(mid):
            result = mid
            lo = mid + 1
        else:
            hi = mid - 1
    
    return result

๐Ÿงช Test Cases

# Test 1: Basic case
flights1 = [(100, 2), (200, 1)]
arrivals1 = [50, 80]
print(latest_arrival_time(flights1, arrivals1))  # Expected: 199

# Test 2: Tight situation
flights2 = [(100, 1)]
arrivals2 = [50]
print(latest_arrival_time(flights2, arrivals2))  # Expected: 49

# Test 3: Impossible to evacuate
flights3 = [(100, 1)]
arrivals3 = [50, 60]
print(latest_arrival_time(flights3, arrivals3))  # Expected: -1

# Test 4: Complex multi-flight scenario
flights4 = [(50, 1), (100, 2), (150, 1)]
arrivals4 = [30, 40, 60, 90]
print(latest_arrival_time(flights4, arrivals4))  # Needs careful analysis

# Test 5: Edge case - no other people
flights5 = [(100, 1)]
arrivals5 = []
print(latest_arrival_time(flights5, arrivals5))  # Expected: 99

# Test 6: Edge case - no flights
flights6 = []
arrivals6 = [50]
print(latest_arrival_time(flights6, arrivals6))  # Expected: -1

Complexity Analysis

Method Time Complexity Space Complexity
Brute Force O(T ร— n ร— m) O(n + m)
Binary Search + Simulation O(log T ร— (n + m) log(n + m)) O(n + m)

Where:


๐Ÿคฏ Interviewer's Followup Traps

Followup 1: What if there are many flights?

Test Point: Optimize the simulation process

Current solution's simulation is O((n + m) log(n + m)). With large n, use Segment Tree or Binary Indexed Tree to optimize seat allocation.

Followup 2: What if you need to return which flight you should take?

def latest_arrival_with_flight(flights, arrivals):
    """Return (latest_arrival_time, flight_index_to_board)"""
    # ... record which flight you board in the simulate function
    pass

Followup 3: What if multiple "you"s all want to arrive as late as possible?

Test Point: Game Theory / Multi-agent Optimization

This becomes a more complex scheduling problem requiring Nash Equilibrium considerations.

Followup 4: What if flights might be delayed?

Test Point: Robustness Design

Need to consider probability models and risk assessment.


๐Ÿ”ฅ Why Most People Fail

Common Mistake Correct Approach
Only consider "can I board" Need to simulate everyone's boarding process
Brute force enumerate all time points Binary search optimization
Ignore "first come first served" rule Greedy strategy: early arrivals board early flights
Poor Edge Case handling No flights, full capacity, time boundaries

๐Ÿ“ž oavoservice Services

This combination of scenario modeling + greedy + binary search is classic Google interview style.

If you encounter similar problems in interviews, we can provide:


๐Ÿ‘‰ Add WeChat Now: Coding0201

Don't let one scheduling problem ruin your Google Offer.


Original content by oavoservice team. Please credit when sharing.