Process Queries on Cart
Problem Overview
- Manage a cart by processing add/remove queries on an integer list.
- Input: initial items array and a query array; Output: final cart array after all queries; n, q ≤ 2e5; IDs up to 1e9; queries are nonzero.
- Positive query appends the ID to the cart; negative query removes the first matching ID; final cart is guaranteed non-empty.
- Real-world context: e-commerce cart prototype.
- From Amazon interviews; a coding interview problem and interview question.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
