Skip to content

Instantly share code, notes, and snippets.

View Vatican-Cameos's full-sized avatar
:electron:
Slow and steady

Pavan Vatican-Cameos

:electron:
Slow and steady
  • University Of Southern California
  • Los Angeles, CA
View GitHub Profile
class Solution:
def longestSubsequence(self, arr: List[int], difference: int) -> int:
opt = [1] * (len(arr) + 1)
for i in range(1, len(arr)):
maxn = 0
for j in range(0,i):
if arr[i] - arr[j] == difference:
if opt[j] > maxn:
maxn = opt[j]
class Solution:
def isMonotonic(self, A: List[int]) -> bool:
i, j = 0, len(A) - 1
state_i, state_j = None, None
while i < len(A)-1 and j > 0:
current_state_i, current_state_j = None, None
if A[i] < A[i+1]:
class Solution(object):
def peakIndexInMountainArray(self, A):
"""
:type A: List[int]
:rtype: int
"""
l = 0
r = len(A) - 1
peak = -1
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: float
"""
# 1 4 6
# 2 3 5
# 1 2 3 4 5 6
class Solution(object):
def numRollsToTarget(self, d, f, target):
"""
:type d: int
:type f: int
:type target: int
:rtype: int
"""
ways = [0]
self.backtrackit(d, f, 0, target, ways)
from random import randrange
class RandomizedSet(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.list = list()
from random import randrange
class RandomizedSet(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.list, self.pos = [], {}
class Solution(object):
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
res = []
self.pahmute(nums,res, list(), 0)
return res
class MaxHeap(object):
def __init__(self,items):
self.heap = []
for item in items:
self.heappush(item)
def heappush(self,item):
heapq.heappush(self.heap, item * -1)
def heappop(self):
def graph_traverse(self, root, k):
parent = collections.deafultdict(set)
queue = []
queue.append(root)
parent[root].add(None)
while queue:
cnode = queue.pop(0)
for node in cnode.adjacent():
queue.append(node)
parent[node].add(node)