Probability Theory
Guess the Word public void findSecretWord(String[] wordlist, Master master) { int n = wordlist.length; // 10 guesses are allowed at most for (int g = 0, matches = 0; g < 10 &&am...
Guess the Word public void findSecretWord(String[] wordlist, Master master) { int n = wordlist.length; // 10 guesses are allowed at most for (int g = 0, matches = 0; g < 10 &&am...
Fundamentals Infix Prefix (RN) Postfix (RPN) a + b + a b a b + a + b * c + a * b c a b c * + ...
Permutations Permutations of multisets [{n \choose m_{1},m_{2},\ldots ,m_{l}}={\frac {n!}{m_{1}!\,m_{2}!\,\cdots \,m_{l}!}}=\frac {\left(\sum_{i=1}^{l}{m_{i}}\right)!}{\prod_{i=1}^{l}{m_{i}!}}] ...
Fundamentals The basic template for prefix sum creation is: vector<int> p(n + 1); for (int i = 0: i < n; i++) { p[i + 1] = p[i] + nums[i]; } // sum[i...j] = p[j + 1] - p[i] Someti...
Best Team With No Conflicts public int bestTeamScore(int[] scores, int[] ages) { int n = ages.length; Integer[] indices = new Integer[n]; for (int i = 0; i < n; i++) { indic...
Arrangement Global and Local Inversions If the 0 occurs at index 2 or greater, then A[0] > A[2] = 0 is a non-local inversion. So 0 can only occur at index 0 or 1. If A[1] = 0, then we must ha...
Arrangement Beautiful Arrangement II public int[] constructArray(int n, int k) { int[] list = new int[n]; // max(k) == n - 1 for (int i = 0, left = 1, right = n; left <= right; i++...
Theorem Triangle area using coordinates [T={\frac {1}{2}}{\big }(x_{A}-x_{C})(y_{B}-y_{A})-(x_{A}-x_{B})(y_{C}-y_{A}){\big }] Triangle inequality In a normed...
Euler’s Theorem In number theory, Euler’s theorem (also known as the Fermat–Euler theorem or Euler’s totient theorem) states that if \(n\) and \(a\) are coprime positive integers, then \(a\) raise...
Pour Water public int[] pourWater(int[] heights, int V, int K) { while (V > 0) { int i = K; while (i > 0 && heights[i] >= heights[i - 1]) { i--; ...