LeetCode solutions

3965. Earliest Finish Time for Land and Water Rides I

My accepted Python solution to LeetCode problem 3965, Earliest Finish Time for Land and Water Rides I, running in 424ms.

  • Difficulty: Easy
  • Python
  • Runtime 424ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 424ms, memory 17.3MB, accepted 2026-01-02.

python
class Solution:
    def earliestFinishTime(self, landStartTime: List[int], landDuration: List[int], waterStartTime: List[int], waterDuration: List[int]) -> int:
        result = float('inf')
        
        # For each land ride
        for i in range(len(landStartTime)):
            land_finish = landStartTime[i] + landDuration[i]
            
            # For each water ride - try water first, then land
            for j in range(len(waterStartTime)):
                water_finish = waterStartTime[j] + waterDuration[j]
                
                # Case 1: Land ride first, then water ride
                # Water can start at max(water start time, land finish)
                water_start_after_land = max(waterStartTime[j], land_finish)
                finish1 = water_start_after_land + waterDuration[j]
                
                # Case 2: Water ride first, then land ride
                land_start_after_water = max(landStartTime[i], water_finish)
                finish2 = land_start_after_water + landDuration[i]
                
                result = min(result, finish1, finish2)
        
        return result

Source