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 corejava; | |
public class PrintEvenOddApproachOne { | |
private static volatile int count = 1; | |
private static final int max = 100; | |
private static volatile boolean odd = true; | |
private static Object lock = new Object(); | |
public static void main(String[] args) throws Exception { |
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 dsa; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class TrieUsingArray { | |
TrieNode root; | |
TrieUsingArray() { |
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 dsa; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
public class Trie { |
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.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class QueueBackedByLinkedList<E> implements Iterable<E> { | |
private Node<E> head; | |
private Node<E> tail; | |
public void enqueue(E item) { | |
Node<E> newNode = new Node<E>(); |
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.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class StackBackedByLinkedList<E> implements Iterable<E> { | |
private Node<E> top; | |
private int n; | |
public StackBackedByLinkedList() { | |
top = 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
import java.util.NoSuchElementException; | |
public class QueueBackedByArray<E> { | |
private E[] elements; | |
private int top; | |
private int rear; | |
private 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
import java.util.Iterator; | |
public class StackBackedByArray<E> implements Iterable<E> { | |
private E[] elements; | |
private int N; | |
public StackBackedByArray(int n) { | |
elements = (E[])new Object[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
package dsa; | |
public class LinkedListRotate { | |
public static void main(String[] args) | |
{ | |
ListNode n1 = new ListNode(1); ListNode n2 = new ListNode(2); ListNode n3 = new ListNode(3); ListNode n4 = new ListNode(4); ListNode n5 = new ListNode(5); | |
n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; | |
System.out.println(getLength(n1)); |
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
public class BackTrackSolution { | |
static int M = 9; | |
static int N = 10; | |
static boolean isValid(int[][] mat, int x, int y, int[][] visitedNodex) { | |
if ( (x >=0 && x < M) && (y >= 0 && y < N) && mat[x][y] == 0 && visitedNodex[x][y] == 0 ) { | |
return true; | |
} |
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
public class GasStationProblem { | |
public static void main(String[] args) { | |
int[] gas = new int[] {1,2,3,4,5}; | |
int[] cost = new int[] {3,4,5,1,2}; | |
// int[] gas = new int[] {2,3,4}; | |
// int[] cost = new int[] {3,4,3}; | |
NewerOlder