Skip to content

Instantly share code, notes, and snippets.

View unnisworld's full-sized avatar

Unnikrishnan unnisworld

View GitHub Profile
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 {
@unnisworld
unnisworld / TrieUsingArray
Created April 10, 2019 14:37
Trie using Array
package dsa;
import java.util.ArrayList;
import java.util.List;
public class TrieUsingArray {
TrieNode root;
TrieUsingArray() {
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 {
@unnisworld
unnisworld / QueueBackedByLinkedList.java
Created March 30, 2019 06:08
Queue backed by linkedlist
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>();
@unnisworld
unnisworld / StackBackedByLinkedList.java
Created March 29, 2019 13:56
Stack backed by linked list
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;
@unnisworld
unnisworld / QueueBackedByArray.java
Created March 29, 2019 03:50
Queue backed by array
import java.util.NoSuchElementException;
public class QueueBackedByArray<E> {
private E[] elements;
private int top;
private int rear;
private int n;
@unnisworld
unnisworld / StackBackedByArray
Last active March 29, 2019 02:48
A stack implementation based on resizable array
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];
}
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));
@unnisworld
unnisworld / Path In NxN maze
Last active March 21, 2019 00:05
Find path in NxN maze - https://www.youtube.com/watch?v=keb6rP07Yqg. This implementation has reversed the role of 0's and 1's. Cells with 1's are occupied and you can travel only through 0's.
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;
}
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};