Skip to content

Instantly share code, notes, and snippets.

View harshitkgupta's full-sized avatar

Harshit Kumar Gupta harshitkgupta

View GitHub Profile
@harshitkgupta
harshitkgupta / RunningMedianHeaps.java
Last active February 19, 2017 05:47
Class to find median in running stream of integers
import java.util.Comparator;
import java.util.PriorityQueue;
class RunningMedianHeaps{
PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>();
PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(Comparator.reverseOrder());
public double getMedian() {
int size = minHeap.size() + maxHeap.size();
@harshitkgupta
harshitkgupta / ArrayUtil.java
Created February 18, 2017 15:22
Utility functions for primitive int array like swap elements, reverse array between startIndex and endIndex and leftRotate array by a shift
/**
This class is used to provide following utilities in primitive array
1- swap elements
2- reverse array between startIndex and endIndex
3- leftRotate array by a shift
*/
class ArrayUtil
{
public static final boolean checkIndexOutOfRange(int[] array, int index)
{