priority-queue:

Max Queue

Implement a MaxQueue class that has the following methods: public interface MaxQueue { public void add(Long l); public Long poll(); public Long pollMax(); } All 3 operations should take on average O(logN) time. Solution // "static void main" must be defined in a public class. public class Main { public static void main(String[] args) throws Exception { System.out.println("Hello World!"); DoubleLinkedList list = new DoubleLinkedList(); MaxQueue maxQ = new MaxQueue(); maxQ.add(5); maxQ.

by lek tin in "algorithm" access_time 3-min read

Kth Largest Element in a Stream

Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Your KthLargest class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method KthLargest.add, return the element representing the kth largest element in the stream.

by lek tin in "algorithm" access_time 2-min read