New update is available. Click here to update.

Last Updated: 23 Sep, 2020

Difficulty: Easy

```
You need to return the product modulo 10^9 + 7.
```

```
If the given array is [1, 4, 2 ,6, 3] and K = 3.
Then answer will be 6 by taking the product of integers 1, 2, and 3.
```

```
Can you solve it in less than O(N * logN) time complexity?
```

```
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains two positive integers 'N' and 'K', where N is the size of the given array 'ARR' and K is the number of elements of the array of which minimum product is to be found.
The next line contains 'N' single space-separated positive integers representing the elements of the array.
```

```
For each test case, print an integer denoting the minimum product of K integers modulo 10^9+7 in a single line.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 10^5
1 <= ARR[i] <= 10^9
1 <= K <= N
Time Limit: 1 sec
```

- Initialize a variable ‘ANS’ to 1 to store the product.
- Build a Max-Heap of the first ‘K’ elements of the given array.
- For each element from ‘K’ to ‘N’, compare it with the root element of the Max-Heap.
- If the element is greater than the root element then ignore it.
- Else pop the root element and add the current element into the heap.

- Multiply all the elements that are currently in the Max-Heap by taking the modulo at each multiplication, and update the variable ‘ANS’.
- Return the ‘ANS’ % ‘MODULO’.

SIMILAR PROBLEMS

Longest Subarray With Zero Sum

Posted: 3 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Sort 0s, 1s, 2s

Posted: 24 Dec, 2022

Difficulty: Easy

Popular Interview Problems: