This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RotatedArray { | |
public boolean isRotated(String s1, String s2){ | |
if(s1.length()!=s2.length()){ | |
return false; | |
} | |
String sAdd = s1 + s1; | |
if(sAdd.contains(s2)){ | |
return true; | |
}else{ | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static Map<Integer, Integer> ht = new HashMap<>();; | |
public static void topView(Node root, int level) { | |
if (root == null) | |
return; | |
Queue<QueuePack> queue = new LinkedList<>(); | |
queue.add(new QueuePack(level, root)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
import java.util.Queue; | |
import java.util.Set; | |
import java.util.TreeMap; | |
public class BottomViewOfBT { | |
public static TreeMap<Integer, Integer> ht = new TreeMap<>();; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
import java.util.Queue; | |
public class T_TreeSizeWithOutRecursion { | |
// If we are not using recursion then we need a data structure to store the | |
// tree traversal, we will use queue here | |
public static int getSize(Node root) { | |
if (root != null) { | |
int size=0; // size of tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Grandparent = React.createClass({ | |
childContextTypes: { | |
message: React.PropTypes.string.isRequired | |
}, | |
getChildContext: function() { | |
return { message: "From Grandparent" }; | |
}, | |
render: function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Approach will be very simple, do any of the tree traversal and check if given element is present. | |
public class T_SearchElementInTree { | |
public static boolean isPresent(Node root, int x) { | |
if (root != null) { | |
// check if current node has the element we are looking for | |
if (root.data == x) { | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
import java.util.Queue; | |
public class T_SearchElementInTreeWithOutRecursion { | |
// If we are not using recursion then we need a data structure to store the | |
// tree traversal, we will use queue here | |
public static boolean isPresent(Node root, int x) { | |
if (root != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Stack; | |
public class PreOrderTree { | |
public void preOrderRecursive(Node root) { | |
if (root != null) { | |
System.out.print(root.data + " "); | |
preOrderRecursive(root.left); | |
preOrderRecursive(root.right); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package T_InorderIteration; | |
import java.util.Stack; | |
public class InorderIretation { | |
public void inorderRecursive(Node root) { | |
if (root != null) { | |
inorderRecursive(root.left); | |
System.out.print(root.data + " "); | |
inorderRecursive(root.right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package T_PostOrder; | |
import java.util.Stack; | |
public class PostorderTree { | |
public void postOrderRecursive(Node root) { | |
if (root != null) { | |
postOrderRecursive(root.left); | |
postOrderRecursive(root.right); |