This repo includes the code that I must remember at all times when I encounter a problem
- Large Array can be declared globally
- Copy by reference + Global Declarations reduces running time
- Avoid endl, it increases runnning time. https://stackoverflow.com/questions/213907/stdendl-vs-n
- Bitsets may be highly useful in reducing complexities
Example: https://www.hackerearth.com/practice/algorithms/graphs/graph-representation/practice-problems/algorithm/utkarsh-in-gardens-february-easy/description/ - Custom Lowerbound Function :https://stackoverflow.com/questions/12968498/compare-function-in-lower-bound
-
Distinct Elements in range l to r using BIT: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/
-
Important DPs:
-
https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/practice-problems/algorithm/number-of-rs-1/
How to detect the application of Maximum Subarray Problem:For a range from 1 to n, at some point i we check ans=max(maxSubArraySum(1...i),maxSubArraySum(i+1...n),maxSumPassingThroughi) which is seen in divide and conquer equivalent of Maximum Subarray Problem
-
Partion such that two subsets have minimum difference:
https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/practice-problems/algorithm/amazing-test/
-
https://www.codechef.com/problems/SPAR3
-
Important 3d dp:
https://www.hackerearth.com/practice/algorithms/dynamic-programming/2-dimensional/practice-problems/algorithm/shift-the-array-4074fac2/description/
Approrach the question using 26^n and then see how to memoize
- Algorithm for finding minimum cycle length in unweighted graph(use bfs and approach below for unweighted undirected graph ) - Complexity O(e^2) [So far minimum complexity for finding min cycle length I have seen] https://www.geeksforgeeks.org/find-minimum-weight-cycle-undirected-graph/
-
Gray Codes differ by one bit in each successive step
- https://www.quora.com/q/competitiveprogramming2/Cut-Vertex-Articulation-point
-
Method to generate subsets of a a number in binary->
Let the number be x and tmp = x, then we can successively compute tmp=(tmp-1)&x, tmp will be the subset -> stop at 0
Example let x = 13, and thus tmp = 13, now :
->First Subset : 13
->Second Subbset : (13-1)&13 = 12
->Third Subset: (12-1)&13 = 9
->Fourth Subset: (9-1)&13 = 8
->Fifth Subset: (8-1)&13 = 5
->Sixth Subset: (5-1)%13 = 4
->Seventh Subset: (4-1)%13 = 1
->Eighth Subset: (1-0)&13 = 0
Reference: Inner loop of suboptimal solution section on https://codeforces.com/blog/entry/45223
-
https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/practice-problems/algorithm/number-of-rs-1/