Disjoint Set
Fundamentals Disjoint-set data structure, also called union-find data structure, stores a collection of disjoint (non-overlapping) sets. Equivalently, it stores a partition of a set into disjoint ...
Fundamentals Disjoint-set data structure, also called union-find data structure, stores a collection of disjoint (non-overlapping) sets. Equivalently, it stores a partition of a set into disjoint ...
Sort Sort List public ListNode sortList(ListNode head) { ListNode dummy = new ListNode(); dummy.next = head; int n = 0; while (head != null) { head = head.next; n+...
Search Reduce to One-dimension Search a 2D Matrix Monotonic in Each Dimenstion Find Positive Integer Solution for a Given Equation public List<List<Integer>> findSolution(CustomFun...
Frog Jump II public int maxJump(int[] stones) { // it's optimal to use of all rocks // it's not optimal to use two consecutive rocks // because on the way back, stones[i + 2] - stones[...
Fundamentals The usual pattern of Tree DFS (or recursion) is: private T1 global; public T2 processTree(TreeNode root) { // call dfs(root) } private T4 dfs(TreeNode node, T3 local) { // ...
N-Repeated Element in Size 2N Array k repeated element in size n array: Find the minimum size m, so that there exists at least one subarray with size m, and it is guaranteed to contain more than ...
Find All Numbers Disappeared in an Array Sort public List<Integer> findDisappearedNumbers(int[] nums) { for (int i = 0; i < nums.length; i++) { int index = nums[i] - 1; ...
Time complexity: Build: O(n) Maximize Sum Of Array After K Negations public int largestSumAfterKNegations(int[] A, int K) { Queue<Integer> pq = new PriorityQueue<>(); Arra...
Ordering https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/stream/package-summary.html Streams may or may not have a defined encounter order. Whether or not a stream has an e...
Representation Nodes from 0 to n: Map<Integer, List<Integer>>: unweighted Map<Integer, Map<Integer, Integer>>: weighted List<Integer>[]: unweighted List<i...