Amazon | Applied Scientist | India | Feb 2024

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-03-19Added By Anonymous
Source: Link

Company: Amazon
Role: Applied Scientist
Interview Stage: Phone Screen
Location: India
Year: 2024

Original Post Content:

Coding Concepts (1hr):

Problem 1:
https://leetcode.com/problems/first-missing-positive/description/

Problem 2:
There is a sale coming on Amazon.in, so sellers are preparing their inventory for the sale, all the sellers putting prices of every item they have. While processing this continuous live data, amazon has to maintain a section of "deal of the day" on its main page where it shows top n items which are least priced. We need to help Amazon to maintain that section for the sale.

Instance 1:
prices = k = {10, 20, 11, 70, 50, 40, 100, 5, ...}
n = 3
Output = {5, 10, 11}

Instance 2:
prices = {10,20, 11, 70, 50, 40, 100, 5, 25, 85, 200, 4, 5, 50, 1000, ...}
n = 5
Output = {4, 5, 5, 10, 11}

Approach:

priority_queue<pair<int, int> > pq; // max heap, to store n minimum prices, along with their index in minimum_prices
vector<int> minimum_prices;

vector<int> min_n_prices(int price){
   if(pq.size)<n){
      pq.push(make_pair(prices[i],minimum_prices.size()));
      minimum_prices.push_back(prices[i]);
   }
   else{
      if(pq.top().first > prices[i]){
         minimum_prices[pq.top().second]=prices[i]
         index = pq.top().second;
         pq.pop();
         pq.push(make_pair(prices[i],index));
      }
   }
   return minimum_prices;
}

Comments