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 abstract class AbstractTreeIterator<E> implements Iterator<E> { | |
protected AbstractTreeIterator(TreeNode<E> root){ | |
assert(root!=null); | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException("remove is not supported"); | |
} |
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 org.idey.algo.datastructure.cache; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class LRUCache<K,V> { | |
private int capacity; | |
private Map<K, Node<K,V>> map = new HashMap<>(); | |
private DoubleLinkedList<K,V> doubleLinkedList=new DoubleLinkedList<>(); |
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 org.idey.algo.datastructure.cache; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.SortedMap; | |
import java.util.TreeMap; | |
public class LFUCache<K,V> { | |
private Map<K, Node<K,V>> map = new HashMap<>(); | |
private Map<K, Integer> counts = new HashMap<>(); |
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 AssertJ { | |
private AssertJ(){ | |
throw new AssertionError("Invalid Access"); | |
} | |
/** | |
* | |
* @param object which will satisfy following code | |
* <pre> | |
* new Predicate<T>(){ |
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 static void printPairUnsorted(int[] array, int sum){ | |
Set<Integer> s = new HashSet<>(); | |
for(int v:array){ | |
int temp = sum - v; | |
if(s.contains(temp)){ | |
System.out.println(String.format("Pair found %d %d", temp,v)); | |
} | |
s.add(v); | |
} | |
} |
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 static String reverseWord(String str){ | |
char[] array = str.toCharArray(); | |
int start=0; | |
int end=array.length-1; | |
reverse(array,0,array.length-1); | |
while (start<=end && array[start]==' ') | |
start++; | |
while (end>=start && array[end] == ' ') | |
end--; |
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 static double findMedian(int[] input1, int[] input2){ | |
if(input1.length>input2.length){ | |
return findMedian(input2,input1); | |
} | |
int x = input1.length; | |
int y = input2.length; | |
int low = 0; | |
int high = x; |
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.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
public class WaterBucket { | |
private static int gcd(int a, int b){ | |
if(a==0) | |
return b; | |
return gcd(b%a, a); | |
} |
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.*; | |
public class Anagrams { | |
private static int[] primeTables; | |
private static void populatePrimeTable(){ | |
if(primeTables==null){ | |
primeTables = new int[128]; | |
PrimeNumber primeNumber = new PrimeNumber(10000); |
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 language.implicitConversions | |
import language.reflectiveCalls | |
/** | |
* This Objects provide safe conversion of [[String]] value to [[Any]] specific type, and return [[Option]] | |
* of the same type after conversion. In case of any exception it will return `None` | |
* Current conversion for following types are supported | |
* `Int`, `Float`, `Double`, `Boolean`, `Short`, `Byte`, `Long`. For any custom type one need to create an | |
* `implicit object` extending `StringConverter` trait | |
* For example |
NewerOlder