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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Minimum product pair an array of positive Integers
- Longest sequence of positive integers in an array
- Find a pair with maximum product in array of Integers
- Minimum increments to convert to an array of consecutive integers
- 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
- Median in a stream of integers (running integers)
- Find distinct integers for a triplet with given product
- Find a number which give minimum sum when XOR with every number of array of integers
- Count of subsequences whose product is a difference of square of two integers
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Program to print N minimum elements from list of integers
- Find integral points with minimum distance from given set of integers using BFS
- Check if the XOR of an array of integers is Even or Odd
- Factorial of an Array of integers
Improved By : sanjeev2552