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.List; | |
import java.util.function.BiPredicate; | |
import java.util.function.Predicate; | |
import static java.util.Arrays.asList; | |
import static java.util.Comparator.*; | |
class IterableSortedTester { |
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.List; | |
import static java.util.stream.Collectors.toList; | |
import java.util.stream.IntStream; | |
import static java.util.stream.IntStream.rangeClosed; | |
public class SieveOfEratosthenes { | |
static boolean isPrime(final int candidate) { | |
if (candidate < 2) { | |
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
import java.util.ArrayList; | |
import java.util.Comparator; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.ListIterator; | |
import java.util.stream.IntStream; | |
import static java.util.concurrent.ThreadLocalRandom.current; | |
class InsertionSort { |
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 static java.lang.Math.ceil; | |
import static java.lang.Math.floor; | |
import static java.lang.Math.pow; | |
import static java.lang.Math.round; | |
import java.util.*; | |
strictfp class A3b3EqualsC3d3 { | |
static class Pair { |
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.*; | |
class CountPairsOfIntegersThatHaveDifferenceK { | |
static int f1(/*distinct*/final int[] A, final int K) { | |
int count = 0; | |
for (int i = 0; i < A.length - 1; i++) { | |
for (int j = i + 1; j < A.length; j++) { | |
if (Math.abs(A[j] - A[i]) == K) { | |
count++; |
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 static java.util.concurrent.ThreadLocalRandom.current; | |
/** | |
* A program finds the largest sum of contiguous subarrays. | |
* | |
* @see <a href="https://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane's_algorithm">Kadane's algorithm</a> | |
*/ | |
class Kadane2 { | |
static long kadane(final int[] A) { |
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.math.BigInteger; | |
import java.util.Arrays; | |
public class FibonacciNumber { | |
static final BigInteger F0 = BigInteger.ZERO; | |
static final BigInteger F1 = BigInteger.ONE; | |
static BigInteger f(final int n) { | |
if (n <= 0) return F0; | |
if (n == 1) return F1; | |
final BigInteger[] a = new BigInteger[] {F0, F1}; | |
for (int i = 2; i < n; 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 SystemEnv { | |
public static void main(final String... args) { | |
System.getenv().entrySet().forEach(e -> System.out.printf("%s: %s\n", e.getKey(), e.getValue())); | |
} | |
} |
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 SystemProperties { | |
public static void main(final String[] args) { | |
System.getProperties().forEach((k, v) -> System.out.printf("%s: %s\n", k, v)); | |
} | |
} |
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 static java.util.concurrent.ThreadLocalRandom.current; | |
/** | |
* A program finds the largest sum of contiguous subarrays. | |
* | |
* @see <a href="https://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane's_algorithm">Kadane's algorithm</a> | |
*/ | |
class Kadane { | |
static long kadane(final int[] A) { |
NewerOlder