Amazon | Online Assessment
Anonymous User
1559

I recently encountered these two questions in an Amazon Online Assessment. I don't remember the names of these questions, but the general idea is as follows -

  1. You are given an integer, requests which denotes the number of requests, and a list wait_time, where wait_time[i] denote the maximum wait time of the i'th request. The requests in the list are served from the first index to the last, and each request will be served for one second, then it is removed from the list (essentially, when you are at index 0, your current time is 0 seconds, then you spend 1 second serving request 0 and remove it from the list). Meanwhile, if some requests in the rest of the list to the right of the current request exceeds it's wait time, then it is removed from the list as well. Return an array denoting how many active requests are present in the list each second.
    Example - requests = 6, wait_time = [5, 2, 2, 4, 7, 1], then output = [6, 4, 2, 2, 1, 0]

  2. You have an integer servers, which denote the number of servers, and you have a list called requests which denote the servers that this request is allowed to be scheduled to. You have to schedule each request to a servers among servers 0 to requests[i] (inclusive) such that it is the least busy server. If multiple servers are the least, use the one with the least index. Return a list containing the server where each request was served.
    Example - servers = 5, requests = [3, 1, 0, 2, 1], then output = [0, 1, 0, 2, 1]

Comments (12)