Skip to content

Instantly share code, notes, and snippets.

public class PrintAllPathIn2DArray {
int rowCount;
int colCount;
int[][] arrA;
public PrintAllPathIn2DArray(int arrA[][]) {
this.arrA = arrA;
rowCount = arrA.length;
colCount = arrA[0].length;
public class CountAllPaths {
int rowCount;
int colCount;
int[][] arrA;
public CountAllPaths(int arrA[][]) {
this.arrA = arrA;
rowCount = arrA.length;
colCount = arrA[0].length;
public class ReverseLinkedList {
static class Node{
public int data;
public Node next;
public Node(int data){
this.data = data;
this.next = null;
}
}
//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
//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;
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;
}
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;
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);
}
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;
}