Skip to content

Instantly share code, notes, and snippets.

View zeitan's full-sized avatar

Antonio Bastardo zeitan

View GitHub Profile
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);
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) {
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()) {
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;
}
private static boolean checkSumInTree(TreeNode root, int k) {
if (root != null)
return checkSumInTreeAcum(root, k, 0);
else
return false;
}
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];
@zeitan
zeitan / Pair.java
Last active May 1, 2020 22:12
sort logs
class Pair<T,S> {
T fst;
S snd;
public Pair(T fst, S snd) {
this.fst = fst;
this.snd = snd;
}
}
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++) {
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;
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);