Skip to content

Instantly share code, notes, and snippets.

View rootChuTney-RaviBhanot's full-sized avatar

Ravi Bhanot rootChuTney-RaviBhanot

  • Mountain View
View GitHub Profile
@rootChuTney-RaviBhanot
rootChuTney-RaviBhanot / DistanceBetweenTwoNodesWithUnbuiltTree.java
Created March 5, 2018 03:52
Given the insertion order of nodes in a binary search tree, find the distance between two nodes in the tree
import java.util.*;
public class DistanceBetweenTwoNodesWithUnbuiltTree {
/*
* Distance between two nodes is number of edges between the two nodes
*/
public static int distanceBetweenTwoNodesofBstWithUnbuiltTree(int[] insertionOrder, int node1, int node2) {
if (insertionOrder == null || insertionOrder.length == 0) {
return -1;