input: Write a function to implement an algorithm that sorts two large lists A and B by comparing the first elements of both lists. If the element from list A is greater than the element from list B, it should append the element from list B to the result list and move the pointer of B to the next element. If the element from A is smaller, it should move the pointer of A to the next element. The function should return the sorted result of both lists combined.
  
      def merge_sort(A, B):
      result = []
      i, j = 0, 0
  
      # Compare elements and add lower one to result
      while i < len(A) and j < len(B):
          if A[i] < B[j]:
              result.append(A[i])
              i += 1
          else:
              result.append(B[j])
              j += 1
  
      # Add remaining elements
      result += A[i:]
      result += B[j:]
  
      return result
  
      # Test the algorithm
      A = [3, 6, 8, 10, 11]
      B = [2, 5, 7, 12]
      assert merge_sort(A, B) == [2, 3, 5, 6, 7, 8, 10, 11, 12]
      assert merge_sort([], [1, 2, 3]) == [1, 2, 3]
      assert merge_sort([1, 3, 5], []) == [1, 3, 5]
      assert merge_sort([], []) == []
      assert merge_sort([4, 7, 9], [2, 6, 8]) == [2, 4, 6, 7, 8, 9]
output: def merge_sort(A, B):
      result = []
      i, j = 0, 0
  
      while i < len(A) and j < len(B):
          if A[i] < B[j]:
              result.append(A[i])
              i += 1
          else:
              result.append(B[j])
              j += 1
  
      result += A[i:]
      result += B[j:]
  
      return result