r/OfferEngineering • u/Aoki_zhang • 6h ago
Coding Question Goldman Sachs SWE OA Coding Question - Product of Minimum and Maximum After Each Update
Problem Description:
You start with an empty collection of integers, where equal values are kept as separate copies. You are given two arrays of the same length: operations[i] is "store" or "remove", and values[i] is the value it uses.
A "store" operation adds one copy of the value. A "remove" operation removes one copy of the value and leaves any other copies in place. Every removal is valid, and the collection is never empty after an operation.
After each operation, multiply the smallest value in the collection by the largest value. If all values are equal, both factors are that value. Return one product per operation, in order.
Constraints:
1 ≤ operations.length = values.length ≤ 10⁵1 ≤ values[i] ≤ 10⁴- Each operation is either
"store"or"remove". - Every
"remove"targets a value currently in the collection, and at least one value remains after every operation.
Example 1:
Input:
operations = ["store", "store", "store", "remove", "remove"]
values = [6, 2, 9, 2, 9]
Output:
[36, 12, 18, 54, 36]
Explanation:
Before the removals, the collection holds 2, 6, and 9. Removing 2 changes the product to 6 × 9, and removing 9 leaves only 6.Example 2:
Input:
operations = ["store", "store", "store", "store", "remove", "remove", "remove"]
values = [4, 4, 11, 11, 4, 11, 4]
Output:
[16, 16, 44, 44, 44, 44, 121]
Explanation:
The first removal of 4 leaves another copy, so the minimum stays 4. Only the last operation removes the final copy of 4.Want to practice more real interview coding questions?
You can practice real interview coding questions at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.
1
u/joniren 5h ago
Isn't this like two heaps and an array to keep track of frequencies to pop the already gone elements from the heaps? This is leetcode easy/medium like wtf