Questions - Print all paths in a binary tree - Function to find the square root of a number - Pretty print JSON object - How would you design home feed? - Simple regex matcher
Anonymous
printing all path in binary tree //printing all the path from root to leaf using recursion public void printRooToLeaf(Node X,List Path){ if(X==null) return; Path.add(X); printRooToLeaf(X.leftChild,Path); printRooToLeaf(X.rightChild,Path); if(X.leftChild==null && X.rightChild==null) { System.out.println("print path from root :"+ root.a+"to leaf"+X.a); for(Node y:Path){ System.out.println(""+y.a); } System.out.println(); } Path.remove(Path.size()-1); }
Check out your Company Bowl for anonymous work chats.