Starting with an empty set of integers named elements
, perform the following query operations:
- The command
push x
inserts the value ofx
intoelements
. - The command
pop x
removes the value ofx
fromelements
.
The integers in elements
need to be ordered in such a way that after each operation is performed, the product of the maximum and minimum values in the set can be easily calculated.
Function Description
Complete the function maxMin
in the editor below.
maxMin
has the following parameter(s):
s[n]
: an array of operations stringsint x[n]
: an array ofx
wherex[i]
goes withoperations[i]
.
Returns
int[n]
: an array of long integers that denote the product of the maximum and minimum of elements
after each query
Example 1:
Input: operations = ["push", "push", "push", "pop"], x = [1, 2, 3, 1]
Output: [1, 2, 3, 6]
Explanation:Visualize
elements
as an empty multiset,elements = {}
, and refer to the return array asproducts
. The sequence of operations occurs as follows:
- push 1 β elements = {1}, so the minimum = 1 and the maximum = 1. Then store the product as
products[0] = 1 Γ 1 = 1
.- push 2 β elements = {1, 2}, so the minimum = 1 and the maximum = 2. Then store the product as
products[1] = 1 Γ 2 = 2
.- push 3 β elements = {1, 2, 3}, so the minimum = 1 and the maximum = 3. Then store the product as
products[2] = 1 Γ 3 = 3
.- pop 1 β elements = {2, 3}, so the minimum = 2 and the maximum = 3. Then store the product as
products[3] = 2 Γ 3 = 6
.Return
products = [1, 2, 3, 6]
1 β€ n β€ 10^5
1 β€ x[i] β€ 10^9
- It is guaranteed that each
operations[i]
is either push or pop. - It is guaranteed that any value popped will exist in the array.
input:
output: