注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
there are 2 LP question- what is your recent project
- could you tell me a time when you have a important, tigh detail project. how you handle it, what is the outcome?
there is 1 coding
// We have logs with a list of requests our service handled, along with their API name, start time and time consumed.
// Assume our server has multiple threads and one thread can handle one request at a given time.
// Let’s design and write a function to determine the minmum number of threads required in this period of time.
// [API1, 1, 3], [API2, 2, 1], [API1, 2, 2], [API1, 5, 8] ( [1,3] 3 threds, [5,8] 1 threads )
// 3
// 1<= request <= 1000
// api name is letter
// 1<starttime<apltime
// 1<= time consumed <= 10000
// 1. sort by start time , minheap sort by end time (starttime + teimcousume)
// 2. loop thru the task array
// 3. add tase to minheap base the start larger than the end time
// 4. keep trace of the size of minheap as ans
// 5. return ans
/*
// Task {
String name
您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 while (!minHeap.isEmpty() && minHeap.peek() <= task.startTime) {
minHeap.pop();
}
minHeap.add(tast.startTime + tast.timeConsumed);
minThreads = Math.max(minThreads, minHeap.size());
}
return minThreads;
}
|