Skip to content

Instantly share code, notes, and snippets.

View Kishy-nivas's full-sized avatar
🏠
Working from home

Kishore Srinivas Kishy-nivas

🏠
Working from home
  • Chennai, India
View GitHub Profile
/*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) {
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;
/*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;
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){
class Node {
int data;
Node next;
Node prev;
}
Node Reverse(Node head) {
if(head == null) return null;
Node temp;
Node curr = head;
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;
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)
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;
}
/*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; }
/*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; }