Given an array of n positive integers. We are required to write a program to print the minimum product of k integers of the given array.
Input : 198 76 544 123 154 675 k = 2 Output : 9348 We get minimum product after multiplying 76 and 123. Input : 11 8 5 7 5 100 k = 4 Output : 1400
The idea is simple, we find the smallest k elements and print multiplication of them. In below implementation, we have used simple Heap based approach where we insert array elements into a min heap and then find product of top k elements.
Minimum product is 9348
Time Complexity : O(n * log n)
This article is contributed by Gitanjali Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum product pair an array of positive Integers
- Only integer with positive value in positive negative value in array
- Flip minimum signs of array elements to get minimum sum of positive elements possible
- Count pairs in Array whose product is a Kth power of any positive integer
- Count of index pairs in array whose range product is a positive integer
- Longest sequence of positive integers in an array
- Number of Subarrays with positive product
- Number of subsequences with positive product
- Length of longest subarray with positive product
- Number of arrays of size N whose elements are positive integers and sum is K
- Longest alternating subsequence in terms of positive and negative integers
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Minimum positive integer required to split the array equally
- Minimum number of changes such that elements are first Negative and then Positive
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k
- Find a pair with maximum product in array of Integers
- Find minimum value to assign all array elements so that array product becomes greater
- Find the smallest positive number missing from an unsorted array | Set 1
- Rearrange array in alternating positive & negative items with O(1) extra space | Set 1
- Find the smallest positive integer value that cannot be represented as sum of any subset of a given array
Improved By : sanjeev2552