Modular Arithmetic
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...
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--; ...
Greedy Minimum Swaps to Make Strings Equal public int minimumSwap(String s1, String s2) { int[] count = new int[2]; for (int i = 0; i < s1.length(); i++) { // ignores matched p...
A* Search A* search algorithm selects the path that minimizes f(n) = g(n) + h(n) where n is the next node on the path g(n) is the cost of the path from the start node to n h(n) is a heuri...
Index Map Longest Substring Without Repeating Characters Dynamic Programming Word Break public boolean wordBreak(String s, List<String> wordDict) { Set<String> dict = new HashSe...
Special Binary String public String makeLargestSpecial(String s) { List<String> list = new ArrayList<>(); int count = 0, i = 0, j = 0; // splits s into as many special stri...
Transformation String Transforms Into Another String public boolean canConvert(String str1, String str2) { if (str1.equals(str2)) { return true; } Map<Character, Character...
Zigzag Iterator public class ZigzagIterator { private Queue<Iterator<Integer>> q; public ZigzagIterator(List<Integer> v1, List<Integer> v2) { q = new Linke...
Read N Characters Given Read4 II - Call multiple times public class Solution extends Reader4 { private char[] buff = new char[4]; private int p = 0; private int count = 0; // count of...
Min Stack stack and minStack Max Stack Two stacks Double linked list + TreeMap Stack + Heap + Set private Deque<int[]> st = new LinkedList<>(); // {element, id of the elemen...