<gh_stars>1-10
import math
# Add any extra import statements you may need here
import heapq

# Add any helper functions you may need here

def get_product(arr, size):
  prod = 1
  for i in range(size):
    prod *= arr[i]
    
  return prod


def findMaxProduct(arr):
  # Write your code here
  size = len(arr)
  res = []  # the output array
  top3_arr = [] # built as a min heap
  for i in range(size):
    if len(top3_arr) < 4:
      heapq.heappush(top3_arr, arr[i])
    if len(top3_arr) < 3:  # in the case therer are less than 3 elements in the candidate array
      res.append(-1)
    elif len(top3_arr) == 3:
      res.append(get_product(top3_arr, 3))
    else:
      heapq.heappop(top3_arr)
      res.append(get_product(top3_arr, 3))
      
  return res



# These are the tests we use to determine if the solution is correct.
# You can add your own at the bottom.

def printInteger(n):
  print('[', n, ']', sep='', end='')

def printIntegerList(array):
  size = len(array)
  print('[', end='')
  for i in range(size):
    if i != 0:
      print(', ', end='')
    print(array[i], end='')
  print(']', end='')

test_case_number = 1

def check(expected, output):
  global test_case_number
  expected_size = len(expected)
  output_size = len(output)
  result = True
  if expected_size != output_size:
    result = False
  for i in range(min(expected_size, output_size)):
    result &= (output[i] == expected[i])
  rightTick = '\u2713'
  wrongTick = '\u2717'
  if result:
    print(rightTick, 'Test #', test_case_number, sep='')
  else:
    print(wrongTick, 'Test #', test_case_number, ': Expected ', sep='', end='')
    printIntegerList(expected)
    print(' Your output: ', end='')
    printIntegerList(output)
    print()
  test_case_number += 1

if __name__ == "__main__":
  arr_1 = [1, 2, 3, 4, 5]
  expected_1 = [-1, -1, 6, 24, 60]
  output_1 = findMaxProduct(arr_1)
  check(expected_1, output_1)

  arr_2 = [2, 4, 7, 1, 5, 3]
  expected_2 = [-1, -1, 56, 56, 140, 140]
  output_2 = findMaxProduct(arr_2)
  check(expected_2, output_2)


  # Add your own test cases here

import math
# Add any extra import statements you may need here
import heapq

# Add any helper functions you may need here

def get_product(arr, size):
  prod = 1
  for i in range(size):
    prod *= arr[i]
    
  return prod


def findMaxProduct(arr):
  # Write your code here
  size = len(arr)
  res = []  # the output array
  top3_arr = [] # built as a min heap
  for i in range(size):
    if len(top3_arr) < 4:
      heapq.heappush(top3_arr, arr[i])
    if len(top3_arr) < 3:  # in the case therer are less than 3 elements in the candidate array
      res.append(-1)
    elif len(top3_arr) == 3:
      res.append(get_product(top3_arr, 3))
    else:
      heapq.heappop(top3_arr)
      res.append(get_product(top3_arr, 3))
      
  return res



# These are the tests we use to determine if the solution is correct.
# You can add your own at the bottom.

def printInteger(n):
  print('[', n, ']', sep='', end='')

def printIntegerList(array):
  size = len(array)
  print('[', end='')
  for i in range(size):
    if i != 0:
      print(', ', end='')
    print(array[i], end='')
  print(']', end='')

test_case_number = 1

def check(expected, output):
  global test_case_number
  expected_size = len(expected)
  output_size = len(output)
  result = True
  if expected_size != output_size:
    result = False
  for i in range(min(expected_size, output_size)):
    result &= (output[i] == expected[i])
  rightTick = '\u2713'
  wrongTick = '\u2717'
  if result:
    print(rightTick, 'Test #', test_case_number, sep='')
  else:
    print(wrongTick, 'Test #', test_case_number, ': Expected ', sep='', end='')
    printIntegerList(expected)
    print(' Your output: ', end='')
    printIntegerList(output)
    print()
  test_case_number += 1

if __name__ == "__main__":
  arr_1 = [1, 2, 3, 4, 5]
  expected_1 = [-1, -1, 6, 24, 60]
  output_1 = findMaxProduct(arr_1)
  check(expected_1, output_1)

  arr_2 = [2, 4, 7, 1, 5, 3]
  expected_2 = [-1, -1, 56, 56, 140, 140]
  output_2 = findMaxProduct(arr_2)
  check(expected_2, output_2)


  # Add your own test cases here
# Add any extra import statements you may need here # Add any helper functions you may need here # Write your code here # the output array # built as a min heap # in the case therer are less than 3 elements in the candidate array # These are the tests we use to determine if the solution is correct. # You can add your own at the bottom. #', test_case_number, sep='') #', test_case_number, ': Expected ', sep='', end='') # Add your own test cases here