Skip to content

Instantly share code, notes, and snippets.

public class SmallestRangeInKList {
public int size;
public HeapNode[] Heap;
public int position;
static int gMax;
static int gMin;
int currMax; //tracks the max entry in the heap
int range = Integer.MAX_VALUE;
public class BSTtoGreaterTree {
public static int sum = 0;
public void greaterTree(Node root){
if(root!=null){
//visit the right node first
greaterTree(root.right);
//store the node value in temp
int temp = root.data;
//update the sum, sum till previous visited node
public class SwapEveryKthNode {
public static void main (String[] args) throws java.lang.Exception
{
LinkedListT a = new LinkedListT();
a.addAtBegin(10);
a.addAtBegin(9);
a.addAtBegin(8);
a.addAtBegin(7);
a.addAtBegin(6);
a.addAtBegin(5);
public class MagicIndex {
// perform modified binary search
public int search(int[] A, int start, int end) {
if (start <= end) {
int mid = (start + end) / 2;
if (mid == A[mid]) // check for magic index.
return mid;
if (mid > A[mid]) { // If mid>A[mid] means fixed point might be on
// the right half of the array
return search(A, mid + 1, end);
public class BinarySearchTree {
public static Node root;
public BinarySearchTree(){
this.root = null;
}
public boolean find(int id){
Node current = root;
while(current!=null){
if(current.data==id){
public class MaxPathSumBwTwoLeaves {
public static int maxSoFar =0;
public int maxPathSum(Node root){
if(root!=null){
int leftS = maxPathSum(root.left);
int rightS = maxPathSum(root.right);
int sumCurrent;
if(leftS<0 && rightS<0){
sumCurrent = root.data;
public class reverseLinkedList2 {
public static Node head=null;
public Node reverseRecur2(Node current){
if(current==null){
return null;
}
if(current.next==null){
head = current;
return null;
}
@thmain
thmain / computeSvgSizeFromData.js
Created January 6, 2016 16:03
d3_tree_min_distance
function computeSvgSizeFromData(config){
var tree = d3.layout.tree(),
nodes = tree.nodes(config.data);
var maxTreeChildrenHeight = {},
maxTreeHeight = 0,
maxTreeDepth = 0,
minSvgWidth,
minSvgHeight;
public class LinkListImplementation {
public static void main(String[] args) throws java.lang.Exception {
LinkedListT a = new LinkedListT();
a.addAtBegin(5);
a.addAtBegin(15);
a.addAtEnd(20);
a.addAtEnd(21);
a.deleteAtBegin();
a.deleteAtEnd();
a.addAtIndex(10, 2);