Question 9 - 100% Working Solution | Buy Now

Description

As an aspiring developer at Amazon, you are building a prototype for a cart management service. There is an array of integers, items, that represents the item ids present in the cart initially. Given an array of qintegers, query, your service must perform as follows. Each integer is an item id to be added to or removed from the cart. - If the query integer is positive, add the integer representing an item id to the back of the cart. - If the integer is negative, remove the first occurrence of the integer from the cart Task Cart Report an array that represents the final cart after processing all the queries. It is guaranteed that the final cart is non-empty and the integers in the integer in the queries are not equal to 0. Example For example. initially, there are n = 5 items in the cart represented as cart = [1, 2, 1, 2, 1] and queries = [-1, -1, 3, 4, -3]. Query
Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution

Please login to view the solution