def _FilterSeenResults(similar_patterns, seen_events):
  """Filters out the similar patterns overlapped with the previous events seen.

  Note that the seconds are approximated with int(), to simplify the algorithm.
  This means that two patterns that are less than a second away will be treated
  as they are overlapped.

  Args:
    similar_patterns: Array of SimilarPatterns.
    seen_events: Array of TimeSpans.
  Returns:
    Array of SimilarPattern without the ones that overlap with the seen events.
  """
  seen_mask = set()
  for seen_event in seen_events:
    start_time = int(seen_event.start_time)
    end_time = int(seen_event.start_time + seen_event.duration)
    for second in range(start_time, end_time + 1):
      seen_mask.add(second)

  filtered_patterns = []
  for pattern in similar_patterns:
    start_time = int(pattern.start_time)
    end_time = int(pattern.start_time + pattern.duration)

    overlaps = any(
        second in seen_mask for second in range(start_time, end_time + 1))
    if not overlaps:
      filtered_patterns.append(pattern)

  return filtered_patterns