Skip to content

Instantly share code, notes, and snippets.

@olee12
olee12 / Euler circuit.cpp
Created October 19, 2019 16:06
Euler circuit or path
map<string, multiset<string> > adj;
vector<string> result; // reverse the result if you are trying to find a path that starts from u.
void dfs(string u) {
while(adj[u].size()) {
string v = *adj[u].begin();
adj[u].erase(adj[u].begin());
dfs(v);
}
return result.push_back(u);
@olee12
olee12 / Search in a 2D Matrix.cpp
Created October 13, 2019 12:24
Search in a 2D sorted Matrix
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (matrix.size() == 0 || matrix[0].size() == 0) return false;
int row = matrix.size();
int col = matrix[0].size();
int low = 0;
int high = row * col - 1;
while (low <= high)
{
@olee12
olee12 / LowerBound.go
Created October 12, 2019 15:07
Lower Bound in golang
// LowerBound ...
func LowerBound(array []int, target int) int {
low, high, mid := 0, len(array)-1, 0
for low <= high {
mid = (low + high) / 2
if array[mid] >= target {
high = mid - 1
} else {
low = mid + 1
}
@olee12
olee12 / UpperBound.go
Created October 12, 2019 14:50
Upper Bound in go.
// UpperBound ...
func UpperBound(array []int, target int) int {
low, high, mid := 0, len(array)-1, 0
for low <= high {
mid = (low + high) / 2
if array[mid] > target {
high = mid - 1
} else {
low = mid + 1
@olee12
olee12 / BinarySearch.go
Last active October 12, 2019 14:48
Binary Search in go.
// BinarySearch ...
func BinarySearch(array []int, target int) int {
low := 0
high := len(array) - 1
mid := 0
for low <= high {
mid = (low + high) / 2
if array[mid] > target {
high = mid - 1
} else if array[mid] < target {
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
@olee12
olee12 / latency.txt
Created July 12, 2019 06:17 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD