FAANG OA
Anonymous User
141

Given an array of array of strings(vector<vector<string>>). Each sub array is of size 3. First element – operation (INSERT, VIEW), second element – name of item, third element – price of item.
For each INSERT operation, we need to insert the item into the database. For each VIEW operation, we are required to print the kth cheapest item from the db.
Once a user visits the page, value of 'k' gets increment by 1.
e.g.,
Suppose initially the db contains {name, price} - {mango, 3) and {apple, 2}.
When user visits the store we will return apple from the db.
Then, we insert two new items – {banana, 1}, {sugarcane, 2} and the user clicks next, then the order in which the data will be stored in the db will be {banana, 1}, {apple, 2}. {mango, 3} {sugarcane, 3}, this is the second visit of user, hence we will return 2nd cheapest item from the db. – {apple, 2}

I had first tried to solve this using vector of pairs and sorting the vector on each insertion. That gave a TLE. Hence, I used Ordered set which is a policy based data structure.
Can anyone confirm as if we are allowed to use policy based data structure in OA?
I could have solved this using binary search on insertion.

Comments (0)