IO
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...
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...
Chunked Transfer Encoding Chunked transfer encoding: HTTP/1.1 Encode and Decode Strings private String toCount(String s) { int length = 4; // 4 chunks char[] bytes = new char[length]; ...
In this type of problem, we linear scan the elements one by one, and use dp[i] to store the state at a certain position. The DP array (1D) can usually be reduced to a DP variable (0D). The general...
Fundamentals Topological sorting: In computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from...
Insert Interval vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) { int n = intervals.size(); vector<vector<i...
Math Chalkboard XOR Game public boolean xorGame(int[] nums) { int xor = 0; for (int num : nums) { xor ^= num; } // when the number of elements are even // not all ele...
Permutation Sequence public String getPermutation(int n, int k) { List<Integer> num = new ArrayList<>(); int fact = 1; for (int i = 1; i <= n; i++) { num.add(i);...
Tenth Line i=0 while (( i++ < 10 )) do read line done < file.txt echo $line tail -n +10 file.txt | head -1 sed -n 10p file.txt AWK Predefined Variables awk divides the input into r...
Update Swap Salary UPDATE salary SET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' END; UPDATE salary SET sex = IF(sex='m', 'f', 'm'); UPDATE salary SET sex = CHAR(ASCII('...