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 whatever //do not write package name here */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class GFG { | |
private static void printLeafNodes(ArrayList < Integer > arr) { | |
if (arr.size() == 0) return; | |
if (arr.size() == 1) { |
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
class GfG { | |
private Node reverse(Node head) { | |
Node curr = head; | |
Node prev = null; | |
Node next = null; | |
while (curr != null) { | |
next = curr.next; | |
curr.next = prev; | |
prev = curr; | |
curr = next; |
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
/*Please note that it's Function problem i.e. | |
you need to write your solution in the form of Function(s) only. | |
Driver Code to call/invoke your function is mentioned above.*/ | |
/* Structure of class Node is | |
class Node | |
{ | |
int data; | |
Node next; | |
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.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
class UnionFind { | |
private int[] parent; | |
private int[] size; | |
public UnionFind(int n){ |
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
class Node { | |
int data; | |
Node next; | |
Node prev; | |
} | |
Node Reverse(Node head) { | |
if(head == null) return null; | |
Node temp; | |
Node curr = head; |
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
class GfG | |
{ | |
Node reverse(Node head){ | |
Node curr = head; | |
Node prev = null; | |
Node next; | |
while(curr != null){ | |
next = curr.next; | |
curr.next =prev; | |
prev = curr; |
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
class GfG | |
{ | |
public HashSet<Integer> set = new HashSet<Integer>(); | |
public void printCommon(Node root1,Node root2){ | |
inOrder(root1); | |
print(root2); | |
//System.out.println(); | |
} | |
public void inOrder(Node root){ | |
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
class GfG | |
{ | |
Node lca(Node node, int n1, int n2) | |
{ | |
Node root = node; | |
while(root != null){ | |
if(root.data>n1 && root.data >n2) | |
{ | |
root = root.left; | |
} |
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
/*Please note that it's Function problem i.e. | |
you need to write your solution in the form of Function(s) only. | |
Driver Code to call/invoke your function is mentioned above.*/ | |
/* The structure of the node of the Linked List is | |
class Node | |
{ | |
int data; | |
Node next; | |
Node(int d) {data = d; next = 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
/*Please note that it's Function problem i.e. | |
you need to write your solution in the form of Function(s) only. | |
Driver Code to call/invoke your function is mentioned above.*/ | |
/* The structure of the node of the Linked List is | |
class Node | |
{ | |
int data; | |
Node next; | |
Node(int d) {data = d; next = null; } |