input: from typing import List
  
  def min_rectangle_area(grid: List[List[int]]) -> int:
      """
      You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.
  
      Return the minimum possible area of the rectangle.
  
      Examples:
      >>> grid = [[0,1,0],[1,0,1]]
      6
      >>> grid = [[1,0],[0,0]]
      1
  
      Constraints:
      1 <= grid.length, grid[i].length <= 1000
      grid[i][j] is either 0 or 1.
      The input is generated such that there is at least one 1 in grid.
      """
  
output: 
      min_row, max_row = len(grid), -1
      min_col, max_col = len(grid[0]), -1
      
      for i in range(len(grid)):
          for j in range(len(grid[0])):
              if grid[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
      
      height = max_row - min_row + 1
      width = max_col - min_col + 1
      
      return height * width
  