next_big_gig
BAN USER- 0of 2 votes
AnswersGiven n number of legacy services with user data<userid, info, date>
- next_big_gig in United States
Design an API to return user data in a given date range, it should collect data from each service and merge and return the data sorted by date.| Report Duplicate | Flag | PURGE
Google Member Technical Staff System Design
Using java synchronized, both deque and enque has to ensure operations are vaild or else wait.
wait until space available for dequing then notifying waiting threads.
public class BlockingQueue {
private List queue = new LinkedList();
private int limit = 10;
public BlockingQueue(int limit){
this.limit = limit;
}
public synchronized void enqueue(Object item)
throws InterruptedException {
while(this.queue.size() == this.limit) {
wait();
}
this.queue.add(item);
notifyAll();
}
public synchronized Object dequeue()
throws InterruptedException{
while(this.queue.size() == 0){
wait();
}
Object obj = this.queue.remove(0);
notifyAll();
}
}
Why downvote ?
- next_big_gig October 27, 2014You will need to remove last inserted element after the recursive call in your for loop.
- next_big_gig October 27, 2014This link as good explanation on how the images are divided into tiles and cached.
all-things-spatial.blogspot.com/2009/06/ingenuity-of-google-map-architecture.html
This solution uses O(1) space and has O(n) time complexity
public int maxProduct(int[] A) {
if (A==null || A.length==0) {
return 0;
}
int pCurrentMax = A[0],
pMaxSoFar=A[0],
pCurrentMin = A[0],
pTempMin, pTempMax;
for (int i =1; i < A.length; i++) {
pTempMax = Math.max(Math.max(A[i]*pCurrentMax, A[i]*pCurrentMin), A[i]);
pTempMin = Math.min(Math.min(A[i]*pCurrentMax, A[i]*pCurrentMin), A[i]);
pMaxSoFar = Math.max(pTempMax, pMaxSoFar);
pCurrentMin = pTempMin;
pCurrentMax = pTempMax;
}
return pMaxSoFar;
}
public int maxSubArray(int[] prices) {
if (prices == null || prices.length < 1) {
return 0;
}
int currentMax = prices[0], max = prices[0];
for (int i=1; i < prices.length; i++) {
currentMax = Math.max(prices[i], currentMax+prices[i]);
max = Math.max(max, currentMax);
}
return max;
}
- next_big_gig April 20, 2015