← 返回 amazon 的题目列表Final Cart Items After Add/Remove Queries
类型:online_judge
amazon
You are building a prototype for a cart management service at Amazon. Given an array of integers, items, that represents the item ids present in the cart. Each integer is:
If the query integer is positive, the item id should be added to the cart.
If the query integer is negative, remove the corresponding item id from the cart.
After processing all queries report the final cart. Ensure the items in the final cart are presented in ascending order.
Example:
Initially, there are no items in the cart represented as cart = [], and the query is queries = [1, -1, 3, 2, -2, -3].
Function Description:
Complete the function findFinalCart.
Parameters:
A list of integers queries where each integer is an add or remove operation for the cart.
Returns: A list of items present in the cart after processing all the operations.
Constraints:
1 ≤ len(queries) ≤ 100000
-10^5 ≤ queries[i] ≤ 10^5
Example
Input
1 -1 3 2 -2 -3