input: Write a Python function that takes a 2D binary array and determines the rectangle with horizontal and vertical sides that has the smallest possible area while enclosing all the 1's in the array.
  
  from typing import List
  
  def smallest_rectangle_area(grid: List[List[int]]) -> int:
      """
      Given a 2D binary array, find a rectangle with horizontal and vertical sides, encapsulating all the 1's within the array and having the minimal area possible.
  
      Examples:
      >>> grid = [[0,1,0],[1,0,1]]
      6
      >>> grid = [[1,0],[0,0]]
      1
  
      Constraints:
      1 <= len(grid), len(grid[i]) <= 1000
      grid[i][j] must be either 0 or 1.
      There is always at least one 1 in the input array.
      """
output: def smallest_rectangle_area(grid: List[List[int]]) -> int:
      min_row, max_row = float('inf'), -float('inf')
      min_col, max_col = float('inf'), -float('inf')
      
      for i in range(len(grid)):
          for j in range(len(grid[i])):
              if grid[i][j] == 1:
                  min_row = min(min_row, i)
                  max_row = max(max_row, i)
                  min_col = min(min_col, j)
                  max_col = max(max_col, j)
      
      return (max_row - min_row + 1) * (max_col - min_col + 1)