input: Write a Python function that takes a 2D binary array as input and determines the smallest rectangle (aligned with the axes) that can encompass all the 1's in the array, then returns the area of that rectangle.
  
  from typing import List
  
  def smallest_encompassing_rectangle(grid: List[List[int]]) -> int:
      """
      You are given a 2D binary matrix. Identify the rectangle with horizontal and vertical sides that has the minimum area necessary to include all the 1's present in the grid. 
  
      Return the least possible area of such a 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] can only be 0 or 1.
      There is at least one 1 in the grid as per the input.
      """
output: def smallest_encompassing_rectangle(grid: List[List[int]]) -> int:
      min_row, max_row = float('inf'), -float('inf')
      min_col, max_col = float('inf'), -float('inf')
      
      for r in range(len(grid)):
          for c in range(len(grid[0])):
              if grid[r][c] == 1:
                  min_row = min(min_row, r)
                  max_row = max(max_row, r)
                  min_col = min(min_col, c)
                  max_col = max(max_col, c)
      
      return (max_row - min_row + 1) * (max_col - min_col + 1)