Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 1.13 KB

File metadata and controls

56 lines (47 loc) · 1.13 KB

gcd

https://en.wikipedia.org/wiki/Euclidean_algorithm

function gcd(a, b)
    if b = 0
        return a
    else
        return gcd(b, a mod b)

prority queue

top get smallest item e.g.

priority_queue<int,vector<int>,greater<>> pq {sticks.begin(), sticks.end()};

api just like stack

class Solution {
public:
    priority_queue<int> q;
    int lastStoneWeight(vector<int>& stones) {
        
        for (int i : stones){
            q.push(i);
        }
        
        while(q.size() > 1){
            int x = q.top();
            q.pop();
            
            int y = q.top();
            q.pop();
            
            if (x-y != 0){
                q.push(x-y);
            }
        }
        return q.size() == 1 ? q.top() : 0;
    }
};

bit manip

xor

a⊕b⊕a=(a⊕a)⊕b=0⊕b=b

lower_bound

find items <= something https://en.cppreference.com/w/cpp/algorithm/lower_bound

Online classes

grokking the system design interview https://www.educative.io/courses/grokking-the-system-design-interview high scalability blog

books