Guy
BAN USER- -4of 8 votes
AnswersWhat would happen if you have only one server for a web cache (a web browser cache whose key is url and value is the loaded content of the webpage) but huge numbers of clients? And how would you solve it? Assume the cache is implemented with a hashmap and a linkedlist.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -1of 3 votes
AnswersCheck if two binary search tree have the same in-order traversal in O(1) space
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - -3of 7 votes
AnswersFind a shortest path in a N*N matrix maze from (0,0) to (N,N), assume 1 is passable, 0 is not, 3 is destination, use memorization to cache the result. Here is my code. I am not sure if I am caching it right.
- Guy in United Statespublic static class MazeResult { public boolean solved; public List<String> res = new ArrayList<String>(); public int steps = Integer.MAX_VALUE; public MazeResult(boolean isSolved) { solved = isSolved; } } static Map<String, MazeResult> cache = new HashMap<String, MazeResult>(); static MazeResult solveMaze(int[][] m, int r, int c, List<String> path, HashSet<String> visited) { if (r < 0 || r >= m.length || c < 0 || c >= m[0].length) return new MazeResult(false); String cell = r + "" + c + ""; if (m[r][c]==0 || visited.contains(cell)) return new MazeResult(false); if (m[r][c] == 3) { MazeResult ret = new MazeResult(true); ret.res = new ArrayList<String>(path); ret.res.add(cell); ret.steps = path.size() + 1; return ret; } if (cache.containsKey(cell)) return cache.get(cell); path.add(cell); visited.add(cell); MazeResult ret = new MazeResult(false), temp = new MazeResult(false); temp = solveMaze(m, r, c+1, path, visited); compareResult(temp, ret); temp = solveMaze(m, r, c-1, path, visited); compareResult(temp, ret); temp = solveMaze(m, r+1, c, path, visited); compareResult(temp, ret); temp = solveMaze(m, r-1, c, path, visited); compareResult(temp, ret); path.remove(path.size()-1); visited.remove(cell); cache.put(cell, ret); return ret; } private static void compareResult(MazeResult temp, MazeResult ret) { if (temp.solved) { if (temp.steps < ret.steps) { ret.res = temp.res; ret.steps = temp.steps; } ret.solved = true; } }
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -1of 3 votes
AnswersGiven a set of intervals, find the interval which has the maximum number of intersections (not the length of a particular intersection). So if input (1,6) (2,3) (4,11), (1,6) should be returned. Some suggest to use Interval Tree to get this done in O(logn), but I did not understand how to construct and use the Interval Tree after reading its wiki page. Is there any other way to do it? If Interval tree is the only option, please educate me how to construct/use one. Thanks.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 2 votes
AnswersFind the k-th Smallest Element in Two Sorted Arrays. I followed the algorithm from this post, http://leetcode.com/2011/01/find-k-th-smallest-element-in-union-of.html
But it does not handle the case where there are duplicates? Does anyone know how to do that? Also, in Java, how should we reduce the size of the arrays? I used the code below, but did not work.
- Guy in United Statespublic static int kthSmallest2(int[] a, int[] b, int k, int a_left, int a_right , int b_left, int b_right) { if (a_left==a_right) return b[k-1]; else if (b_left==b_right) return a[k-1]; int m = a_right-a_left, n=b_right-b_left; int i = (int)((double)m / (m+n) * (k-1)); // i can be any number // make sure i + j = k - 1 // int i = (a_left+a_right)/2 + k/2; // i can be any number int j = k - 1 - i; int bj_1 = 0, ai_1 = 0; if (i==0) { ai_1 = Integer.MIN_VALUE; } // in case i = 0, outOfBound else { ai_1 = a[i-1]; } if (j==0) { bj_1 = Integer.MIN_VALUE; } // in case j = 0, outOfBound else { bj_1 = b[j-1]; } if (bj_1 < a[i] && a[i] < b[j]) // kth smallest found, b[j-1] < a[i] < b[j] return a[i]; if (ai_1 < b[j] && b[j] < a[i]) // kth smallest found, a[i-1] < b[j] < a[i] return b[j]; if ( a[i] < b[j] ) // if true, exclude a's lower bound (if 2 arrays merged, a's lower bound must // reside before kth smallest, so also update k. // also exclude b's upper bound, since they are all greater than kth element. return kthSmallest2(a, b, k, i+1, a.length-1, 0,j-1); else return kthSmallest2(a, b, k, 0, i-1, j+1, b.length-1); }
| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -2of 2 votes
AnswerDesign a meeting scheduler. The solution I came up with was to create an array of intervals for each day, so if intervals is 15 mins, then array size would be 24*4. However, if interval is small, that will substantially increase the size of the array, and that might be considered as a waste of space, though it supports O(1) look up. I was wondering if there is any other way to do this. I think we might be able to keep a sorted array of meetings sorted by start time, so look up would be O(logn). But insertion in the middle of the array would take O(n) since it requires data shifting.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - -2of 2 votes
AnswersDesign a meeting scheduler. One way is to use an array to represent each interval, like every 15 mins. Although it provides O(1) look up, if interval is small, it seems like we are wasting a lot of space. Any alternative approach that can save space? If we keep a sorted array of meetings sorted by start time, look up will be O(logn), but inserting the new meeting in the middle of the array will require shifting elements, which is O(n).
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 0of 4 votes
AnswersFinding a pair of elements from two sorted lists(or array) for which the sum of the elements is a certain value. Anyway solution that can do better than O(a.length + b.length)?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -6of 6 votes
AnswersGiven a preorder traversal, create a binary search tree in optimized time
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -2of 2 votes
AnswersHow to design an elevator system. Main thing to worry about is how would you notify the elevator that it needs to move up or down. and also if you are going to have a centralized class to control this behavior and how could you distribute the control.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Object Oriented Design - -4of 6 votes
AnswersGiven a binary tree, how would you copy it from one machine to the other, assume you have a flash drive. I believe we should write the binary tree to file and have the other machine de-serialize it. But how should we do it?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -2of 2 votes
Answersarray where indexes correspond to the tree node number of a parent node, and values correspond to current tree node number., root having number -1 Write code to recreate a tree. (I was confusing about what the array index and value really represent)
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - -11of 11 votes
Answerslargest number that an int variable can fit given a memory of certain size
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -5of 7 votes
AnswersImplement a class to create timer object in OOP
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Object Oriented Design - -9of 9 votes
AnswersWhat's the tracking algorithm of nearest location to some friends that are located in a grid region?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -5of 7 votes
AnswersHow would you split a search query across multiple machines?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -5of 7 votes
AnswersGiven a list of strings. Produce a list of the longest common suffixes. If it asks for longest common substring, then building a suffix tree should be the way to go. But how should we implement this if it is for longest common suffixes?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -6of 6 votes
AnswersIf you have data coming in rapid succession what is the best way of dealing with redundant data?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Data Structures - -7of 7 votes
AnswersHow would you use Dijkstra's algorithm to solve travel salesman problem, which is to find a shortest path from a starting node back to the starting node and visits all other node exactly once.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -3of 5 votes
AnswersHow does trie handle scalability as opposed to hashtable? Assuming it is used for a dictionary. Sclability here should cover large size of input, running out of memory, or even running out of memory on multiple machines if distributed system is used.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - 5of 9 votes
AnswersWrite a Program for Dictionary which has functionality of lookup and insert . This program should be able to add words on the fly
- Guy in United States
I wrote simple code using HashTable
follow up
1) Now we are getting too many words what happens
me: Hashtable will dynamically resize resulting into performance hit . Also they might get hashed to same location as well as we might run out of main memory
2) Okay you are out of main memory , How will you scale this program
me: I will create buckets of HashTable lets say 26 buckets for one for each alphabet and would put them on different machines
3) Lets say you are out of memory on those machines too
me: Okay I need to put them on secondary storage . Here we can have fileSystem or Database . I chose database . I will create simple DB schema of BucketNumber and word .
I will use buckets on main memory as cache , if we are not able to find a word in the bucket then query databse with bucket number and words then remove the least number times looked up word (every time we lookup a word we increament the count i.e value in key,value pair on hashtable) from that bucket and add this word .
I mentioned that bottleneck in this case will be every time a word is not present we need to query DB which usually has high latency which will result into performance hit
4) Lets say we are okay with latency but what if we are getting inserting words between that are only between only in two buckets ex. words starting from a and b only.
Now that I think about it, is it better to do this in a trie? What do you guys think?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design - -3of 3 votes
AnswersFind a triplet that sum to a given value in an array of integers. I know it can be done in O(n^2) with either using a hashmap(space O(n)) or pre-sorting(space O(1)) the array. Is there any way to do this better than O(n^2)?
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 4 votes
AnswersDesign a program that would select which elevator in a building would be the most efficient, based on where the elevator is located and headed and where the user is located and headed.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Object Oriented Design - 0of 4 votes
AnswersPrint all the elements in an array that have occurred an odd number of times. I know we can XOR all numbers, but that only solves the problem where there is only one odd number in the array. But I was asked to find all of them. Another method I can think of is to keep one hashset, then walk through the array, if the number is in the map, remove it. If the number is not present, add it. But this requires O(n) space. Is there any way to do this with O(n) time and O(1) space?
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - -8of 8 votes
Answerssort the array so that the odd number in front of the even number and their relative order doesn't change in Time O(n) and Space O(1). I believe quickselect can do this, but it will change the relative order of the input.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -1of 5 votes
AnswersWhat happens during and after a query is being typed (autocomplete) in a search box whether the user is trying to go to a website or asking a question etc, and how do servers complete the request and what is the best (parallel) structure for the request to go through. DFS and how servers are located for proximity
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -1of 5 votes
AnswersWrite code to return a random line from a file of unknown size and variable length rows
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -3of 5 votes
AnswersHow would you design a chess game in OOP?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Object Oriented Design - -3of 5 votes
AnswersGiven inputs from Google Search, you have K chunks. Each chunk is individually alphabetically ordered (apple, banana, cat) ... (*apple, *banan, *cat). You want to merge all chunks into a single list. How would you do it?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -3of 7 votes
AnswersCount the number of positive integers less than N that does not contains digit 4.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -11of 13 votes
AnswersIf you had a savings account with $1, at a 100% interest rate, at what year would you have 15 billion dollars? I know it's Log base 2 of 15 billion. But how did it get to log base 2? What's the formula here?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Math & Computation - -3of 5 votes
AnswersThe setup is that we are given a series of text files which contain information regarding a code repository's commits. Each file represents a single commit and they are formatted as follows:
- Guy in United States
"
Commit #: XXX
Author: XXX
Reviewer(s): XXX, XXX, ...
File: XXX
File: XXX
...
Date: XX:XX:XX XX/XX/XXXX
"
The commit number is unique and is generated in synchronous order. There is exactly 1 unique author. There are a variable number of reviewers, delimited by commas; if there are no reviewers, that line is absent from the file. There are a variable number of edited files in the commit, each receiving its own line. The time/date is when the commit was submitted.
First design a graphical model for all of the commit data. Then describe how this model is updated when a new commit is generated. Finally, write the code segment called when a new commit is generated which edits a system that has implemented your model of the data - its input is a file name and whatever necessary data structures that are maintained by your system.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -1of 1 vote
AnswersHow to design a file system in OOP. I believe we can use composite pattern to model in which we create an abstract class say Entry, and have directories and files extend from it. In Directories, it has a List<Entry>. How should we write the remove method so that it will recursively remove all of its sub-directories and sub-files then do parent.remove(this)? Also, how should we take read/write permission into account?
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Object Oriented Design - -1of 3 votes
AnswersHow would you design a social network and find or keep track of someone's oldest friend in a social network? Oldest friend means the friend that you have added for the longest time period. My solution to the first question is to represent friendship in a graph , storing a list of friends in each User object, and use breadth-first-search to find connection. Not sure about the second question though. My idea is either keep a reference to the oldest friend as a member field, or have a double linked list of users sorted by the start date of friendship.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design - 0of 4 votes
AnswersGiven a kernal code in "0"th machine. How soon you can replicate the kernal across N machines. Now if the machines has upload and download bandwidth constraints, how can you impove the copy time.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Operating System - -1of 3 votes
AnswersGiven a log file from a website which contains the user ID and the accessed URL, find the TOP "sequence" of 3 urls amongst ALL visitors of the website. The sequence of urls have to be in sequence as they are accessed.
- Guy in United States
My solution is Two hashtables and one MaxUrl object. One hashtable<String,String> userName as key and url sequence as value, where url sequence is three url contatenated by a special character like '#' (google#amazon#yahoo). This value is in FIFO manner. For each value, we check with the second hashtable and see if they exist before, if yes, increment the count, if no, insert the new sequence with count set to 0. So second hashtable<String, Integer> url sequence as key and count as value. Keep a curr_Max to store the current max count, when exceeded, updates max_urlSequence.
Any suggestion?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures - 0of 2 votes
AnswersHow to design a zoo in oop? Some basic ideas are to have an abstract Animal class and have birds, mammal extend from it. Also have a class called Cages with different size. Zoo will contain a list of animal, list of cages, probably some workers. What else should I add and how could we improve the design? Thanks.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Object Oriented Design - 1of 3 votes
AnswersHow would you synchronize a linked list across multiple computers. If nodes are added/removed to a linked list on one computer, all others must reflect this change. Concurrancy must be accounted for. (java)
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - 1of 3 votes
AnswersFind the shortest path in a maze (from origin to destination). I believe we are supposed to use Dijkstra or BFS. But what I am confused with is that Dijkstra computes the shortest path based on the distance of each edge. But a maze doesn't have weighted edges, and its shortest path should be 'minimum number of cells'. How can we make use of Dijkstra, or BFS?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -1of 1 vote
AnswersDifference between cloning a directed graph vs undirected graph. There are lots of tutorials on how to clone a directed graph online, such as leetcode. But what if it's undirected graph? It appears to me that it would be pretty much the same? For example,
public class Node() { public int data; public ArrayList<Node> adjacent; }
For example, A can have a neighbor called B. Therefore, we may traverse from A to B. For undirected graph, does it imply that B can always traverse back to A? Even if it does, if we use a hashtable to keep track of which node has been copied and processed in the queue, then the logic for cloning a directed graph should be the same as for a undirected graph, right?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 1of 3 votes
AnswersDoes a given file name match a single-star pattern? (can't use regex I assume)
- Guy in United States
index.html matches *.html
foo.txt does not match *.html
matches(“index.html”, “*html”) returns true
matches(“foo.txt”, “*html”) returns false
matches(“cat”, “c*t”) returns true| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 4of 8 votes
AnswersGiven a set top box:
- Guy in United States
a, b, c, d, e,
f, g, h, i, j,
k, l, m, n, o
p, q, r, s, t
u, v, w, x, y
z
Write code to give the character sequence given a word, For example, if the word is "CON", the function will print this:
Right//now we're at B
Right//now we're at C
OK//to select C
Down
DOwn
Right
Right
OK//to select O
Left//now at N
OK//to select N
note: Be careful when you're at Z. if you go to the right, you will get stuck.
Afterwards, the interviewer adds a space to the right of 'Z' to test the code.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 4 votes
AnswersDesign Short URL. (I am not sure what it even means)
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -1of 1 vote
AnswersGiven two Binary trees. these trees "may" have right and left branches swapped. Now compare it.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - -1of 1 vote
AnswersGiven a undirected graph, clone it. Now if the undirected graph has the neighbors with the nodes as same data - how do you make sure you create the exact same branches and also how do you make sure you don't run into loops for the exact node. He gave a empty directed graph and asked me write code after that.
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -5of 7 votes
AnswersThere's a matrix. Each element in the matirx is a bit (0 or 1). Write a method to reverse this matrix. The matrix is stored in a one dimensional char array. The length of each row is given.
- Guy in United States
How do you improve your solution when handling large amount of data?| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -1of 1 vote
AnswersDesign a object oriented class for a vending machine. My idea is that it should have the ability to take in money, item selection, serving item. But I am not sure how to put everything together using good object-oriented principles.
- Guy in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Object Oriented Design - -2of 6 votes
AnswersGiven a list of integers that fall within a known short but unknown range of values, how to find the median value?
- Guy in United States
Some say we could use selection algorithm. But that will take O(n/2 * n), which results in O(n^2). I don't know how it is a good solution.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - -1of 3 votes
AnswersWrite a method which takes an array input and returns true if the sum of any two elements is equal to the sum of the corresponding indices. Like if for an array the sum of values at any two indices i and j is equal to the sum of i and j.
- Guy in United States
I can't think of any other way to do it except brute force.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - -1of 1 vote
AnswersImplement classes for a website that can be used for building your own computer in object-oriented design manner. Eg: If a user selects a motherboard, it should filter out all the incompatible CPUs etc. You have to implement various classes that can be used for implementing this functionality. Java preferred.
- Guy in United States
Thanks a lot.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer System Design - -1of 3 votes
AnswersThere is a matrix which contains white cells , black cells and only one gray cell, need to go from (0,0) to (N-1, N-1) if Arra[N][N]
- Guy in United States
constraints:
a. The path should cover only white cells and should go via grey cell.
b. The node once visited cannot be visited again.
White cells are represented by 0, black cells by 1 and grey cell by 2.
Java preferred.
I know there is another thread on the same problem, but apparently nobody has the correct solution there. Most of the suggested solution won't cover all cases.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 2 votes
AnswersHow would you model the animal kingdom (with species and their behavior) as a class system?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -4of 6 votes
AnswersHow would you model the animal kingdom (with species and their behavior) as a class system? Java
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design - -2of 4 votes
AnswersHow would you model the animal kingdom (with species and their behavior) as a class system?
- Guy in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer System Design
- 3 Answers Amazon said they liked me but the position is no longer open and asked me to wait?
I went through all phone interviews and an onsite interview with Amazon in Irvine office a few weeks ago. The recruiter called me and said they really liked and wanted to work with me, but the position I originally applied is no longer open. He asked me if I wanted to go to Seattle; if so, he could transfer my case to Seattle and see if there is a match. I said I wanted to stay in southern California. He then said I would need to wait for the next open position with the same level and asked me to check back in in a month. I asked how long is the estimated wait. He responded that he couldn't give me a fixed time, but given the growth of Amazon in Irvine, it takes about 30 or 60 days. Then he emphasized that this is not a bad news as in we reject you, and that they do like me and want to work with me, it's just the position is not open anymore and ask me to check in with him in a month.
- Guy March 11, 2014
So what are my chances now? He didn't guarantee anything. My friends say I should have a very good chance. When I did the onsite interview, all interviewers were from different team. So I didn't interview with a specific team. Should I continue looking? But actively interviewing is very tiring and time-consuming. If my chances are good, I really want to just wait a month or two.| Flag | PURGE
Could anyone please explain what the question really asks for? input: <"Height","NumberOfTall","Name">,
<6,2,"A">,<1,4,"B">,<11,0,"C">,<5,1,"D">,<10,0,"E">,<4,0,"F">
output: "F","E","D","C","B","A" --> end of queue?
Looks like the queue is simply the reverse order of the input list.
My algorithm is O(nlogn + m*n), where m is the maximum number of intersections with any single interval.
Sort the interval by both start points and end points. Keep track of the active segments. When reaching a start point, increment the intersection counts of all active intervals, and set the new interval's intersection count to the number of active intervals (excluding itself). When reaching an end point, remove the interval from the active intervals.
So worst case would be O(n^2). Can we do better than this?
Well, first of all, I don't see any problem sharing questions here even though I didn't get asked. This is a place for people to share questions that they have heard of directly or indirectly. Secondly, I am not called Kevin. Third, I never asked for answers for any of the problems. I am simply asking for the right directions and approach. If you call that as "memorize", then I got nothing to say to you. Take care.
- Guy February 12, 2014Given your solution doesn't handle synchronization and timing, which I believe is good enough for a 45-min interview, how do you distribute the control? Like how does your system notify the closest or the first available found elevator to go to certain floor, and how do you use the priorityQueue?
- Guy February 11, 2014I just figured my approach of having each elevator to have a queue and trying to synchronize and taking timing issue (the time for an elevator to get to a floor) will make this problem very complex. I tried to write it on paper, but dont think it works. It seems like we don't really need to take concurrency or timing issue into account here, but we do need to somehow use a queue to distribute the control. Any suggestion?
- Guy February 11, 2014My idea is to make Elevator implement Runnable, and constantly check a queue (linkedList). A Controller class will assign which floor to go in the queue. When the queue is empty, the run() method will wait (queue.wait() ), when a floor is assigned to this elevator, it will call queue.notify() to wake up the run() method, and run() method will call goToFloor(queue.pop())
- Guy February 11, 2014
Yeah. I hope someone from Amazon or has recruiting experience can answer this.
- Guy March 12, 2014