Skip to content

Instantly share code, notes, and snippets.

void balanceSets() {
// from left to mid, elements move in to the mid
sum += balanceLR(left, mid, k);
// from mid to right, elements move out from the mid
sum -= balanceLR(mid, right, m - 2 * k);
}
int balanceLR(multiset<int> &l, multiset<int> &r, int n) {
// tracks how much should the running sum change in value
int diff = 0;
@zzandland
zzandland / percentile.py
Created December 10, 2019 05:28
Count percentile
class Node:
def __init__(self, n: int):
self.val = n
self.left = self.right = None
def percentageUnderNum(root: Node, threshold: int, depth: int) -> float:
def helper(node: Node, count: int, total: int, curDepth: int) -> [int]:
output = [count, total]
if not node or curDepth > depth:
return output
" ============================================================================
" Active plugins
" You can disable or add new ones here:
" this needs to be here, so vim-plug knows we are declaring the plugins we
" want to use
call plug#begin('~/.config/nvim/plugged')
" Now the actual plugins:
@zzandland
zzandland / count_island.py
Created August 9, 2019 00:23
count_island
class Ocean:
def __init__(self, size):
self.board = [None] * (size * size)
self.size = size
self.cnt = 0
def find(self, a):
return self.board[a] = find(self.board[a])
def union(self, a, b) -> bool:
def chunked_palindrome
#include <iostream>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
int sum_sq(int n) {
int n_sqrt = sqrt(n);
set<int> sqrs;
@zzandland
zzandland / largest-level-of-tree.js
Created October 11, 2018 16:48
Largest level of tree
var findLargestLevel = (node) => {
// make levelObj as closure var
const levelObj = {};
// inner function takes in node and level
const innerFunc = (node, level) => {
// if levelObj doesn't have property at this level
if (levelObj[level] === undefined) {
// create a new value, with the node inside an array
levelObj[level] = [node];
// otherwise