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
| package com.practice.codingblocks; | |
| import java.util.HashMap; | |
| import java.util.HashSet; | |
| public class SlidingWindow { | |
| private static int maximumWindowSum(int[] arr, int k) { |
-
Run the application : a) Either do --> java -jar path_to_userfeed.jar b) Or if have maven --> mvn spring-boot:run
-
Once done, run a curl command (POST) localhost:8080/setup?userId=1 [This will set the friends (follower) list (2, 3) for this user.]
-
Now, you can create posts for this user, run a curl command (POST) localhost:8080/post a) This requires JSON to be send as requestBody, for example : { "userId" : 1
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.time.LocalDateTime; | |
| import java.time.OffsetDateTime; | |
| public class RequestEntry { | |
| private LocalDateTime localDateTime; | |
| public RequestEntry(final LocalDateTime localDateTime) { | |
| localDateTime.toEpochSecond(OffsetDateTime.now().getOffset()); | |
| this.localDateTime = localDateTime; |
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; |
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.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.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.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
| 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) { | |
| /* |