Line Segment Problem
Number of Sets of K Non-Overlapping Line Segments private static final int MOD = (int)1e9 + 7; public int numberOfSets(int n, int k) { long[][] dp = new long[n][k + 1]; dp[0][0] = 1; ...
Number of Sets of K Non-Overlapping Line Segments private static final int MOD = (int)1e9 + 7; public int numberOfSets(int n, int k) { long[][] dp = new long[n][k + 1]; dp[0][0] = 1; ...
Fenwick tree (Binary indexed tree) A Fenwick tree or binary indexed tree is a data structure that can efficiently update elements and calculate prefix sums in a table of numbers. public class Fen...
Redis Redis (Remote Dictionary Server) Documentation Redis Cluster Interview questions In-memory key-value data store. Stores cache data into physical storage if needed. Executes ultra...
Check if There is a Valid Partition For The Array public boolean validPartition(int[] nums) { boolean[] dp = {true, false, nums[0] == nums[1], false}; int n = nums.length; for (int i =...
Minimum Amount of Time to Fill Cups public int fillCups(int[] amount) { int max = 0, sum = 0; for (int a : amount) { max = Math.max(max, a); sum += a; } // 1 cup of...
Fundamentals Segment tree Efficient range query, while array modification is flexible. Implementation Recursive The standard (recursive, top-down) Segment Tree requires \(4n\) vertices for wor...
Iteration Length of the Longest Valid Substring private static final int MAX_FORBIDDEN_LEN = 10; public int longestValidSubstring(String word, List<String> forbidden) { Set<String&g...
Divide and conquer + Memoization. Maximum Value of K Coins From Piles private Integer[][] memo; public int maxValueOfCoins(List<List<Integer>> piles, int k) { this.memo = new Int...
Majority element: an element that occurs repeatedly for more than half of the elements of the input. Boyer-Moore Voting Algorithm Boyer–Moore majority vote algorithm: finds the majority of a sequ...
The dynamic programming problems are not self-contained, i.e. external information are required. Burst Balloons public int maxCoins(int[] nums) { int n = nums.length; // dp[i][j]: max co...