Skip to content

Instantly share code, notes, and snippets.

@radkol
radkol / ContainerWithMostWater.java
Created October 19, 2020 16:03
ContainerWithMostWater
class Solution {
public int maxArea(int[] height) {
int i = 0;
int j = height.length - 1;
int max = Integer.MIN_VALUE;
while (i < height.length && j > 0 && i < j) {
@radkol
radkol / CustomHashMap.java
Created October 12, 2020 12:58
CustomHashMap
package com.primeholding.training.create;
import java.util.LinkedList;
public class CustomHashMap<K, V> {
LinkedList<Pair<K, V>>[] storage = new LinkedList[10];
public void put(K key, V value) {
int val = key.hashCode();
@radkol
radkol / CanBuildSticksSquare.java
Created October 8, 2020 17:59
CanBuildSticksSquare
class Solution {
public boolean makesquare(int[] nums) {
// less than 4 sticks, false
if(nums.length < 4) {
return false;
}
// find total
int total = 0;
@radkol
radkol / CombinationSum.java
Last active October 8, 2020 10:54
combinationSum
class Solution {
public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> result = new ArrayList<>();
_combine(0, candidates, new ArrayList<>(), target, result);
return result;
}
void _combine(int idx, int[] src, List<Integer> current, int target, List<List<Integer>> result) {
@radkol
radkol / DistanceFromLeaf.java
Created October 2, 2020 14:38
DistanceFromLeaf
static Set<TreeNode> findLeafDistanceNodes(TreeNode<Integer> node, int distance) {
Set<TreeNode> result = new HashSet<>();
_findLeafDistanceNodes(node, new ArrayList<>(), result, distance);
return result;
}
static void _findLeafDistanceNodes(TreeNode<Integer> node, List<TreeNode> current, Set<TreeNode> result, int lvl) {
if(node == null) {
return;
@radkol
radkol / FindWord.java
Created September 29, 2020 09:33
FindWord
package com.primeholding.training.codility.attempt2.live;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class Task {
@radkol
radkol / PossibleSumsDP.java
Created September 24, 2020 11:08
PossibleSumsDP
package com.primeholding.training.dp;
import java.util.HashMap;
public class PossibleSumsDP {
public static void main(String[] args) {
int[] src = {1, 2, 4, 5, 10, 15, 16};
@radkol
radkol / ClimbingStairs.java
Created September 24, 2020 05:29
ClimbingStairs
package com.primeholding.training.dp;
import java.util.HashMap;
import java.util.Map;
public class ClimbingStairs {
public static void main(String[] args) {
int res = climbStairs(4);
System.out.println(res);
@radkol
radkol / StringPermutation.java
Created September 18, 2020 14:08
StringPermutation
package com.primeholding.training;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.parameters.P;
public class StringPermutation {
public static void main(String[] args) {
@radkol
radkol / IntegerPermutations.java
Created September 18, 2020 14:07
IntegerPermutation
package com.primeholding.training;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class IntegerPermutations {
public static void main(String[] args) {