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.concurrent.BlockingQueue; | |
| public class ConsumerTask implements Runnable { | |
| private static final int H1 = 0; | |
| private static final int H2 = 1; | |
| private static final int H3 = 2; | |
| private static final int H4 = 3; | |
| final static int LIMIT = 100; |
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.SortedMap; | |
| import java.util.TreeMap; | |
| public class ConsistentHashing { | |
| // Consistent Hashing with Ring having 50 buckets. | |
| final static int LIMIT = 50; | |
| // Sorted Map. | |
| final static SortedMap<Integer, String> bucketIdToServer = new TreeMap<>(); |
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.io.IOException; | |
| import java.net.URL; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.util.ArrayList; | |
| import java.util.BitSet; | |
| import java.util.List; | |
| import java.util.concurrent.ThreadLocalRandom; | |
| import java.util.stream.Stream; |
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 DoublyLinkedList { | |
| private int size = 0; | |
| private Node last, first; | |
| public void addLast(Node node) { | |
| if (first == null) { | |
| first = node; | |
| last = first; |
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 AutoSuggestion { | |
| private static final int TEN_THOUSAND_REQUESTS = 10000; | |
| private static final int START = 0; | |
| private static final String SEPARATOR = "--------------------------------------------------------------------" + | |
| "---------------------------------------------------------------"; | |
| public static void main(String[] args) { | |
| /* |
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.HashSet; | |
| import java.util.Objects; | |
| import java.util.Set; | |
| import java.util.Stack; | |
| public class FloodFill { | |
| private static final String SEPARATOR = "--------------------------------------------------------------------"; | |
| private static final int[][] directions = new int[][]{ |
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.Comparator; | |
| import java.util.HashSet; | |
| import java.util.Objects; | |
| import java.util.Set; | |
| import java.util.Stack; | |
| import java.util.TreeSet; | |
| public class ConnectedCells { | |
| private static final String SEPARATOR = "--------------------------------------------------------------------"; |
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.Arrays; | |
| import java.util.HashSet; | |
| import java.util.Objects; | |
| import java.util.Set; | |
| public class Boggle { | |
| private static final int[][] DIRECTIONS = new int[][]{ | |
| {0, 1}, // E | |
| {1, 0}, // S |
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.concurrent.ConcurrentHashMap; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; | |
| import java.util.concurrent.ThreadLocalRandom; | |
| public class TokenBucket { | |
| public static final ConcurrentHashMap<String, TokenEntry> userTokenCount = new ConcurrentHashMap<>(); | |
| public final static int API_LIMIT_FOR_EACH_USER = 5; |
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.concurrent.ArrayBlockingQueue; | |
| import java.util.concurrent.BlockingQueue; | |
| import java.util.concurrent.RejectedExecutionHandler; | |
| import java.util.concurrent.ThreadLocalRandom; | |
| import java.util.concurrent.ThreadPoolExecutor; | |
| import java.util.concurrent.TimeUnit; | |
| public class LeakyBucket { | |
| public static final int API_REQUEST_LIMIT_OF_THE_SERVER = 5; |
OlderNewer