input: from typing import List
  
  def smallest_rectangle_covering_all_ones(matrix: List[List[int]]) -> int:
      """
      Given a 2D binary array matrix, determine the rectangle with the smallest area that can enclose all the 1's in the matrix.
  
      Return the minimum area of this rectangle.
  
      Examples:
      >>> matrix = [[0,1,0],[1,0,1]]
      6
      >>> matrix = [[1,0],[0,0]]
      1
  
      Constraints:
      1 <= matrix.length, matrix[i].length <= 1000
      Each element of matrix is either 0 or 1.
      The input is guaranteed to contain at least one 1.
      """
output:     min_row, max_row = float('inf'), float('-inf')
      min_col, max_col = float('inf'), float('-inf')
      
      for i in range(len(matrix)):
          for j in range(len(matrix[0])):
              if matrix[i][j] == 1:
                  if i < min_row:
                      min_row = i
                  if i > max_row:
                      max_row = i
                  if j < min_col:
                      min_col = j
                  if j > max_col:
                      max_col = j
                      
      return (max_row - min_row + 1) * (max_col - min_col + 1)