Editorialist: Aditya Prajapati
You’ve got a set of instructions by which you can add an element to a list (insert k), remove all occurences of an element from the list (delete k), and get the sum of the minimum and maximum elements of the list (sum). You have to print the sum of the minimum and maximum elements of the list when you encounter a sum instruction.
We have to maintain a list and add numbers to it when an insert instruction is found. So, if we have
our list will be . Now, if similarly 3, 5 and 2 are added again, the list will be
[2, 3, 5, 2]
Now, whenever a delete instruction is found, we will remove all occurences of that number from the list. Example:
So, the list will be:
When a sum instruction is found, we need to print the sum of the minimum and maximum elements of the list.
Maintain a python set.
Add k to set when insert k is encountered.
Remove k from set when delete k is encountered.
When sum is encountered, cast set to list and use the max and min properties of the list to get maximum and minumum values, add these and print them.
Editorialists’ solution can be found here.