Skip to content

Instantly share code, notes, and snippets.

View jumpgame.py
class Solution:
def canJump(self, nums: List[int]) -> bool:
if len(nums)==1:
return True
minjump=1
idx=len(nums)-2
while idx >= 0:
if nums[idx]>=minjump:
minjump=1
View fineGrainLocking.cc
#include <sys/time.h>
//#include "queues.h"
#include <iostream>
#include <thread>
#include <atomic>
#include <deque>
#include <mutex>
#include <optional>
#include <vector>
@jeb2239
jeb2239 / ordered_dict.py
Created Jan 21, 2021 — forked from joequery/ordered_dict.py
Python 3.5.0b1 OrderedDict implementation
View ordered_dict.py
# Located in Lib/collections/__init__.py
################################################################################
### OrderedDict
################################################################################
class _OrderedDictKeysView(KeysView):
def __reversed__(self):
yield from reversed(self._mapping)
@jeb2239
jeb2239 / trie.py
Last active Jan 8, 2021 — forked from nhudinhtuan/trie.py
Trie Data Structure
View trie.py
class TrieNode(object):
def __init__(self):
self.children = {}
self.is_word = False # mark the end of a word
class Trie(object):
def __init__(self):
View someq.py
'''
Lets say N ppl go on a trip, each spend some amount of money. Write a function to print out the how to split the money evenly, and minimize the number of transactions.
assumptions
N > 1
input int/dec
time: NlogN
space: O(1)
min. # of transactions: N-1
View interviewProblem
//
// Given a very large array that is composed by
//
// n elements in descending order, followed by
// m elements in ascending order,
//
// find the position where the order gets reversed.
//
// Example:
// INPUT: [9,8,6,5,4,6,8,10,34,56]
View main.py
#buggy code took 20 minutes
class Solution:
def validateBinaryTreeNodes(
self, n: int, leftChild: List[int], rightChild: List[int]
) -> bool:
nparent = [0] * n
for i in range(n):
leftv = nparent[leftChild[i]]
View file.py
import heapq as hq
import sys
import math
from typing import NamedTuple
class Entry(NamedTuple):
cost:int
node:int
class Solution:
View binarysearch---rodCutting.py
# https://binarysearch.com/problems/Rod-Cutting
class Solution:
def solve(self, prices, n):
memoRec=[-1]*(n+1)
def rodCutRec(rodLeft,prices):
if memoRec[rodLeft]!=-1:
return memoRec[rodLeft]