Skip to content

Instantly share code, notes, and snippets.

View zeitan's full-sized avatar

Antonio Bastardo zeitan

View GitHub Profile
private static String buildProducts(String parts) {
int acumA = 0;
int acumB = 0;
int acumC = 0;
int acumD = 0;
int acumE = 0;
for (int i = 0; i < parts.length(); i++) {
switch (parts.charAt(i)) {
case 'a' : ++acumA;
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);
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 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++) {
@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;
}
}
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];
private static boolean checkSumInTree(TreeNode root, int k) {
if (root != null)
return checkSumInTreeAcum(root, k, 0);
else
return false;
}
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;
}
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()) {
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) {