Regex
String public boolean matches(String regex) Validate IP Address public String validIPAddress(String IP) { if (IP.matches("^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?...
String public boolean matches(String regex) Validate IP Address public String validIPAddress(String IP) { if (IP.matches("^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?...
Elastic-size Window The constraint can be expressed as: [f(v) \ge 0] where \(v\) is called contraint variable. Constraint variable is determined by the position and size of the sliding window: ...
Merge K Sorted Lists public ListNode mergeKLists(ListNode[] lists) { int k = lists.length; if (k == 0) { return null; } int interval = 1; while (interval < k) { ...
A spanning tree T of an undirected graph G is a subgraph that is a tree which includes all of the vertices of G. A minimum spanning tree (MST) or minimum weight spanning tree is a spanning tree wh...
Fundamentals Level traversal. The most common data structure used is Queue. Two rolling Lists or Sets (de-dupe) can also be used, but less common. Smallest Greater Multiple Made of Two Digits Im...
Dijkstra Fundamentals Dijkstra’s algorithm Dijkstra’s Shortest Path First algorithm (SPF algorithm) is an algorithm for finding the shortest paths between nodes in a graph. A single node as the ...
NavigableSet Prefix Suffix Parameter Comparison ceiling e >= floor e <= ...
Java Methods NavigableMap Prefix Suffix Parameter Comparison ceiling entry/key key >= floor entr...
Shuffle Fisher-Yates shuffle Shuffle an Array private int[] arr; private int[] oldArr; private Random rand = new Random(); public Solution(int[] nums) { arr = nums; oldArr = nums.clone...
Fundamentals Knapsack problem Backtracking takes \(O(2^n)\) time, so it’s less preferable. Dynamic Programming is better, and its form is like dp[i][j], which means the first i elements sums to j...