[Amazon OA] Merge files (priority queue) and frontapp/backapp allocation (binary search)
Anonymous User
458

First question: Merge files https://leetcode.com/discuss/interview-question/1112834/Amazon-OA-SDE-2

Second question:
Give you a list of frontapp tasks idx and its required memory, each list first value is its unique id and second value is its required memory.
front = [[1,2],[2,4],[3,5]] etc
And a list of backapp tasks as well. end = [[1,3],[2,2],[3,10]]

Requirement: there is one device with max capacity of targetCapacity. This device only supports one task of frontapp and one task of backapp (and frontapp and backapp tasks have to run simultaneously). Find ALL the pairs that have the MAXIMUM capacity under the requirement of device maximum capacity.

  1. I used binary search to search through the frontapp / backup with larger number of tasks.
  2. Using binary search only returns the last one task pair that meets the requirement. But the task memory is not unique when means task 1,2,3 could have the same memory required. Therefore, this is a tricky scenario. I added a hash map to store the mapping between memory and its corresponding task IDs.
Comments (0)