input: 
  def longest_common_subsequence(str1: str, str2: str) -> str:
      """ Finds the longest common subsequence (LCS) between two strings.
      >>> longest_common_subsequence("ABACEDF", "ABDCF")
      'ABCF'
      >>> longest_common_subsequence("ABCBDAB", "BDCABA")
      'BCBA'
      """
      m, n = len(str1), len(str2)
  
      # Create a 2D array to store lengths of longest common subsequence.
      lcs_array = [[0] * (n + 1) for i in range(m + 1)]
  
      # Build the array from bottom to top
      for i in range(m + 1):
          for j in range(n + 1):
              if i == 0 or j == 0:
                  lcs_array[i][j] = 0
              elif str1[i - 1] == str2[j - 1]:
                  lcs_array[i][j] = lcs_array[i - 1][j - 1] + 1
              else:
                  lcs_array[i][j] = max(lcs_array[i - 1][j], lcs_array[i][j - 1])
  
      # Start from the bottom-right corner and track back to the start
      index = lcs_array[m][n]
      lcs_result = [""] * (index + 1)
      lcs_result[index] = ""
  
      i, j = m, n
      while i > 0 and j > 0:
          if str1[i - 1] == str2[j - 1]:
              lcs_result[index - 1] = str1[i - 1]
              i -= 1
              j -= 1
              index -= 1
          elif lcs_array[i - 1][j] > lcs_array[i][j - 1]:
              i -= 1
          else:
              j -= 1
  
      return "".join(lcs_result)
  
  # Test the function
  print("LCS is ", longest_common_subsequence("ABACEDF", "ABDCF"))
  
output:     
      m, n = len(str1), len(str2)
  
      # Create a 2D array to store lengths of longest common subsequence.
      lcs_array = [[0] * (n + 1) for i in range(m + 1)]
  
      # Build the array from bottom to top
      for i in range(m + 1):
          for j in range(n + 1):
              if i == 0 or j == 0:
                  lcs_array[i][j] = 0
              elif str1[i - 1] == str2[j - 1]:
                  lcs_array[i][j] = lcs_array[i - 1][j - 1] + 1
              else:
                  lcs_array[i][j] = max(lcs_array[i - 1][j], lcs_array[i][j - 1])
  
      # Start from the bottom-right corner and track back to the start
      index = lcs_array[m][n]
      lcs_result = [""] * (index + 1)
      lcs_result[index] = ""
  
      i, j = m, n
      while i > 0 and j > 0:
          if str1[i - 1] == str2[j - 1]:
              lcs_result[index - 1] = str1[i - 1]
              i -= 1
              j -= 1
              index -= 1
          elif lcs_array[i - 1][j] > lcs_array[i][j - 1]:
              i -= 1
          else:
              j -= 1
  
      return "".join(lcs_result)
  
  # Test the function
  print("LCS is ", longest_common_subsequence("ABACEDF", "ABDCF"))
  