This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/time.h> | |
//#include "queues.h" | |
#include <iostream> | |
#include <thread> | |
#include <atomic> | |
#include <deque> | |
#include <mutex> | |
#include <optional> | |
#include <vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Located in Lib/collections/__init__.py | |
################################################################################ | |
### OrderedDict | |
################################################################################ | |
class _OrderedDictKeysView(KeysView): | |
def __reversed__(self): | |
yield from reversed(self._mapping) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode(object): | |
def __init__(self): | |
self.children = {} | |
self.is_word = False # mark the end of a word | |
class Trie(object): | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq as hq | |
import sys | |
import math | |
from typing import NamedTuple | |
class Entry(NamedTuple): | |
cost:int | |
node:int | |
class Solution: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello |
NewerOlder