Subsequence
Definition a[i_0], a[i_1], ..., a[i_k] Where 0 <= i_0 < i_1 < ... < i_k <= a.length Algorithm Greedy Shortest Impossible Sequence of Rolls public int shortestSequence(int[] roll...
Definition a[i_0], a[i_1], ..., a[i_k] Where 0 <= i_0 < i_1 < ... < i_k <= a.length Algorithm Greedy Shortest Impossible Sequence of Rolls public int shortestSequence(int[] roll...
Definition a[i], a[i + 1], ..., a[j] Where 0 <= i <= j <= a.length Algorithm Minimum Moves to Make Array Complementary public int minMoves(int[] nums, int limit) { // delta array ...
Distant Barcodes Let n = barcodes.length. Find the elements barcodes[i] with the most occurrences \(o_{max}\). Assume an element barcodes[k] has occurences \(o_k\). Steps: Put barcodes[i] to t...
Semaphore Semaphore Conceptually, a semaphore maintains a set of permits. Semaphore(int): a bowl of marbles acquire(): takes one marble from the bowl; waits if there are none release(): ad...
Edit Distance public int minDistance(String word1, String word2) { int n1 = word1.length(), n2 = word2.length(); // dp[i][j]: word1.substring(0, i) -> word2.substring(0, j) int[][]...
Underscores in Numeric Literals In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to...
Array Empty array: int[] arr1 = new int[0]; int[][] arr2 = new int[0][0]; ArrayDeque Null elements are prohibited. Arrays public static <T> List<T> asList(T… a): fixed-size, mu...
Binary Search public int search(int[] nums, int target) { int low = 0, high = nums.length - 1; while (low <= high) { int mid = (low + high) >>> 1; if (nums[mid]...