Skip to content

Instantly share code, notes, and snippets.

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
#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 January 21, 2021 13:34 — forked from joequery/ordered_dict.py
Python 3.5.0b1 OrderedDict implementation
# Located in Lib/collections/__init__.py
################################################################################
### OrderedDict
################################################################################
class _OrderedDictKeysView(KeysView):
def __reversed__(self):
yield from reversed(self._mapping)
@jeb2239
jeb2239 / trie.py
Last active January 8, 2021 02:24 — forked from nhudinhtuan/trie.py
Trie Data Structure
class TrieNode(object):
def __init__(self):
self.children = {}
self.is_word = False # mark the end of a word
class Trie(object):
def __init__(self):
@jeb2239
jeb2239 / someq.py
Created December 24, 2020 00:07
somequestion
'''
Let’s 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
@jeb2239
jeb2239 / interviewProblem
Created December 16, 2020 14:23
a problem
//
// 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]
@jeb2239
jeb2239 / main.py
Created November 30, 2020 18:13
1361
#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]]
import heapq as hq
import sys
import math
from typing import NamedTuple
class Entry(NamedTuple):
cost:int
node:int
class Solution:
@jeb2239
jeb2239 / binarysearch---rodCutting.py
Last active November 13, 2020 15:53
codeProblems
# 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]
@jeb2239
jeb2239 / todos---remind.txt
Last active November 12, 2020 15:32
todos
hello