A Product Pair

Published by Mubashir Hassan in

Mubashir needs your help in the simple task of multiplication of elements in a given array.

Create a function that takes an array of integers arr and a positive integer k and returns the minimum and maximum possible product of k elements taken from the array. If enough elements are not available in the array, return nil.

Examples

product_pair([1, -2, -3, 4, 6, 7], 1) ➞ [-3, 7]

product_pair([1, -2, -3, 4, 6, 7], 2) ➞ [-21, 42]
# -3*7, 6*7

product_pair([1, -2, -3, 4, 6, 7], 3) ➞ [-126, 168]
# -3*6*7, 4*6*7

product_pair([1, -2, -3, 4, 6, 7], 7) ➞ nil
# There are only 6 elements in the array

Notes

N/A

Watch a quick demo on how Edabit works.