Product of the Maximum and Minimum in a Dataset
Learn this problemProblem statement
Starting with an empty set of integers named elements, perform the following query operations:
- The command
push xinserts the value ofxintoelements. - The command
pop xremoves the value ofxfromelements.
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
maxMin(operations: String[], x: int[]) → int[]
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 ofxwherex[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
Examples
Example 1
operations = ["push", "push", "push", "pop"]x = [1, 2, 3, 1]return = [1, 2, 3, 6]
Visualize elements as an empty multiset, elements = {},
and refer to the return array as products. 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]
Constraints
1 ≤ n ≤ 10^51 ≤ 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.
More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Word LadderPHONE SCREEN · Seen Jun 2026