Skip to content

Instantly share code, notes, and snippets.

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;
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));
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<>();;
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
var Grandparent = React.createClass({
childContextTypes: {
message: React.PropTypes.string.isRequired
},
getChildContext: function() {
return { message: "From Grandparent" };
},
render: function() {
//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;
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) {
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);
}
}
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);
package T_PostOrder;
import java.util.Stack;
public class PostorderTree {
public void postOrderRecursive(Node root) {
if (root != null) {
postOrderRecursive(root.left);
postOrderRecursive(root.right);