LeetCode solutions

1028. Interval List Intersections

My accepted Python solution to LeetCode problem 1028, Interval List Intersections, running in 7ms.

  • Difficulty: Medium
  • Python
  • Runtime 7ms
  • Memory 18.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 18.3MB, accepted 2025-12-30.

python
class Solution:
    def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
        result = []
        i = j = 0
        
        while i < len(firstList) and j < len(secondList):
            start = max(firstList[i][0], secondList[j][0])
            end = min(firstList[i][1], secondList[j][1])
            
            if start <= end:
                result.append([start, end])
            
            if firstList[i][1] < secondList[j][1]:
                i += 1
            else:
                j += 1
        
        return result

Source