Amazon Interview Question
Solutions EngineersCountry: United States
Interview Type: Phone Interview
Why do we need PQKeyVal datastructure? Can't we do somethong like below?
public static void merge(List<Stream> inputStreams, Stream outputStream) {
PriorityQueue<Stream> q = new PriorityQueue<Stream>();
for (Stream s: inputStreams) {
q.add(s);
}
for (;;)
{
Stream top = q.poll();
outputStream.put(top.poll());
q.offer(top);
}
}
where PQKeyVal defined like that:
- Anonymous October 06, 2019