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 FindSetBits { | |
public static int getTotalSetBits(byte[] b, int offset, int endIndex) | |
{ | |
int size = b.length; | |
length = endIndex - offset; | |
if(offset > size*8) throw new IllegalArgumentException("Offset overflow"); | |
if((offset + length )> size*8) throw new IllegalArgumentException("Offset overflow"); | |
int startIndex = offset; |
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.Iterator; | |
import java.util.PriorityQueue; | |
import java.util.Queue; | |
/** | |
KDTrees. Used to find KNearestNeighbour among N Points in a KD Plane in O(logK) time. | |
Here is the implementation of 2D tress to find K nearest neighbours for any point among N given points. | |
Run time complexity : O((N+k)logK). |
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 facebook.onlinequiz; | |
import java.io.InputStreamReader; | |
import java.io.IOException; | |
import java.io.BufferedReader; | |
import java.util.StringTokenizer; | |
public class Solution { | |
int totalTests = 0; |
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.HashMap; | |
import java.util.Map; | |
public class RetrieveShuffledSentence { | |
static ArrayList<String> origDictWords ; | |
static Map<String, String> dictMap; | |
public static void populateDictionary(String[] dict) | |
{ |
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 TextJustification { | |
public static void justifyText(String[] words, int width) | |
{ | |
if(words == null || words.length == 0) return ; | |
//checkForIllegalArgs(words, width) TO DO | |
int start = 0; |
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 TextJustification { | |
public static void justifyText(String[] words, int width) | |
{ | |
if(words == null || words.length == 0) return ; | |
//checkForIllegalArgs(words, width) | |
int start = 0; | |
int end = 0; | |
int wordLen = words.length; |
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 NoStarveReaderWriterLock { | |
private final Semaphore readMutex = new Semaphore(1); | |
private final Semaphore writeMutex = new Semaphore(1); | |
private final Semaphore noStarveMutex = new Semaphore(1); | |
private final Set<Long> readerIds = Collections | |
.synchronizedSet(new HashSet<Long>()); | |
private volatile Long writerId; | |
public void readLock() { | |
try { |
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.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
public class LuckyStrings { | |
public static void main(String args[]) throws NumberFormatException, IOException | |
{ |
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
/** | |
* Class used for scrubbing the log for any inconsistencies | |
*/ | |
public class Scrubber { | |
/** | |
* Used to start scrubbing the log for consistency checks | |
*/ | |
public void start(); |
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 com.github.ambry.clustermap.PartitionId; | |
import com.github.ambry.config.StoreConfig; | |
import com.github.ambry.store.BlobStore; | |
import com.github.ambry.utils.Time; | |
import java.util.Map; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.ThreadLocalRandom; | |
import java.util.concurrent.TimeUnit; |
OlderNewer