This file contains hidden or 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 MergeTwoLinkList { | |
private LinkedListT a; | |
private LinkedListT b; | |
public MergeTwoLinkList(LinkedListT a, LinkedListT b) { | |
this.a = a; | |
this.b = b; | |
} |
This file contains hidden or 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 PrintAllPathIn2DArray { | |
int rowCount; | |
int colCount; | |
int[][] arrA; | |
public PrintAllPathIn2DArray(int arrA[][]) { | |
this.arrA = arrA; | |
rowCount = arrA.length; | |
colCount = arrA[0].length; |
This file contains hidden or 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 CountAllPaths { | |
int rowCount; | |
int colCount; | |
int[][] arrA; | |
public CountAllPaths(int arrA[][]) { | |
this.arrA = arrA; | |
rowCount = arrA.length; | |
colCount = arrA[0].length; |
This file contains hidden or 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 ReverseLinkedList { | |
static class Node{ | |
public int data; | |
public Node next; | |
public Node(int data){ | |
this.data = data; | |
this.next = null; | |
} | |
} |
This file contains hidden or 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
//Find the Loop | |
//Take two pointers, both starts from head | |
//move one pointer with normal speed and another with double speed | |
//if both pointers meets at some point, we have found the loop | |
//Now find the loop length | |
//at the point where both pointers have met, stop one pointer and keep moving the nother one | |
//when another pointer meets the first pointer, stop. | |
//keep counting number of hops, that will your loop length | |
//Now To break the loop | |
//move one pointer by the loop length |
This file contains hidden or 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
//find the length of both the linked lists say : a_len and b_len | |
//find the lenDiff = (a_len ~ b_len) | |
//traverse the longer linked list by lenDiff | |
//Now traverse both the lists at the same time | |
//check whether nodes are same, if yes then we have found the intersection point | |
//if we reach the end of the link lists then there is no intersection point. | |
public class FindIntersectionOfLinkedLists { | |
public LinkedListIntersection a; | |
public LinkedListIntersection b; |
This file contains hidden or 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.HashMap; | |
import java.util.Iterator; | |
import java.util.Set; | |
public class PermutationStrings { | |
public boolean isPermutation(String s1, String s2){ | |
if(s1.length()!=s2.length()){ | |
return false; | |
} |
This file contains hidden or 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.HashMap; | |
public class RD { | |
public Node removeDup(Node head){ | |
HashMap<Integer, Integer> ht = new HashMap<Integer, Integer>(); | |
if(head==null){ | |
return null; | |
} | |
Node currNode = head.next; | |
Node prevNode = head; |
This file contains hidden or 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 KthToLastElementofLL { | |
public int kthByRecursion(Node head, int k){ | |
if(head==null){ | |
return 0; | |
} | |
int i = kthByRecursion(head.next, k)+1; | |
if(i==k){ | |
System.out.println(head.data); | |
} |
This file contains hidden or 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 deleteMiddleNodeInLL { | |
public void deleteMiddle(Node mid){ | |
if(mid.next==null){ | |
return; // we cant delete the node if it is the last node in the linked list | |
} | |
Node curr = mid; | |
curr.data = curr.next.data; | |
curr.next = curr.next.next; | |
} |