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 static int countScore(String[] T, String[] R) { | |
Map<String, Boolean> groups = new HashMap<>(); | |
int countOkIndividualTests = 0; | |
int countIndividuals = 0; | |
final String OK = "OK"; | |
for (int i = 0; i < T.length; i++) { | |
String nameTest = T[i]; | |
Character lastCharacter = nameTest.charAt(nameTest.length() -1); | |
if (lastCharacter >= 'a' && lastCharacter <= 'z') { | |
String nameGroup = nameTest.substring(0, nameTest.length() - 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.util.Map; | |
import java.util.TreeMap; | |
import java.util.Arrays; | |
import java.util.Set; | |
import java.util.TreeSet; | |
public class Strobogrammatic { | |
private Map<Integer, String[]> numbersGenerated = new TreeMap<>(); | |
public Strobogrammatic(int initialSize) { |
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 static int calculateMaxShipment(List<Shipment> shipmentList) { | |
int highShipment = -1; | |
int counter = 0; | |
Map<Integer, Integer> hours = new TreeMap<>(); | |
for (Shipment shipment : shipmentList) { | |
hours.put(shipment.in, hours.getOrDefault(shipment.in, 0) + 1); | |
hours.put(shipment.out, hours.getOrDefault(shipment.out, 0) - 1); | |
} | |
for (Map.Entry<Integer, Integer> hourEntry : hours.entrySet()) { |
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
private static boolean areSame(String arr) | |
{ | |
char first = arr.charAt(0); | |
for (int i = 1; i < arr.length(); i++) | |
if (arr.charAt(i) != first) | |
return false; | |
return true; | |
} |
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
private static boolean checkSumInTree(TreeNode root, int k) { | |
if (root != null) | |
return checkSumInTreeAcum(root, k, 0); | |
else | |
return false; | |
} |
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 Trie { | |
String key; | |
Trie[] character = null; | |
// Constructor | |
Trie() | |
{ | |
// Trie supports lowercase English characters (a - z) | |
// so character size is 26 | |
character = new Trie[26]; |
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 Pair<T,S> { | |
T fst; | |
S snd; | |
public Pair(T fst, S snd) { | |
this.fst = fst; | |
this.snd = snd; | |
} | |
} |
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
private static Set<Set<Integer>> calculatePowerSet(Set<Integer> list) { | |
int size = list.size(); | |
Set<Set<Integer>> powerSet = new HashSet<>(); | |
powerSet.add(Collections.EMPTY_SET); | |
if (size == 0) { | |
return powerSet; | |
} | |
Integer[] elems = list.toArray(new Integer[size]); | |
int end = (int) Math.pow(2, size) - 1; | |
for (int i=1; i<= end; i++) { |
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 LRUCache { | |
class Entry { | |
int key; | |
int value; | |
Entry left; | |
Entry right; | |
public Entry(int key, int value, Entry left, Entry right) { | |
this.key = key; | |
this.value = value; |
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
private static int findKthSmallestNumber3(int[] data, int low, int high, int k) { | |
if (k > 0 && k <= high - low + 1) { | |
int partitionCalculated = partition(data, low, high); | |
if (partitionCalculated - 1 == k -1 ) { | |
return data[partitionCalculated - 1 ]; | |
} | |
if (partitionCalculated - 1 > k -1) { | |
return findKthSmallestNumber3(data, low, partitionCalculated - 1, k); |
NewerOlder