Skip to content

Instantly share code, notes, and snippets.

View adamgarcia4's full-sized avatar

Adam Garcia adamgarcia4

  • Atlanta, Georgia
View GitHub Profile
@adamgarcia4
adamgarcia4 / cloudSettings
Last active March 25, 2020 18:30
Wix Coding Challenge
{"lastUpload":"2020-03-25T18:30:15.275Z","extensionVersion":"v3.4.3"}
# 1004: Max ConsecutiveOnes III
maxLength = 0
numZeros = 0
# 1052: Grumpy Bookstore Owner
maxCustWhenGrumpy = 0
idxOfStartX = 0
custWhenGrumpy = 0
# 1456: Max Number of Vowels in Substring of given length
Interval Operations
There are a few operations that can be performed on intervals:
1. Merge interval[] s.t. the all intervals are disjoint.
[0,5],[5,7] ==> [0,7]
2. Insert interval into interval[] s.t. all intervals are disjoint.
3. Find intersection between two interval[].
[0,5],[5,7] => [5,5]
In order to perform these operations, it is important to understand the 6
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
'''
left subtree needs to be balanced
right subtree needs to be balanced
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def flatten(self, root: TreeNode) -> None:
"""
Do not return anything, modify root in-place instead.
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
'''
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def inorderTraversal(self, node: TreeNode) -> List[int]:
stack = []
class Solution:
def helper(self, numOpen, numClosed, n, solutionSoFar, result):
# Goal
if numOpen == n and numClosed == n:
result.append(solutionSoFar)
return
# Choice
# Choice 1: Place an open parenthesis
class Solution:
# 'i' is the choice for nums[i].
# partialSolution: []
def getSolution(self, partialSolution, nums):
res = []
for idx, num in enumerate(nums):
if partialSolution[idx] == 1:
res.append(num)
return res
class Solution:
def getHappyString(self, n: int, k: int) -> str:
'''
Input:
n - the length of a happy string
k - I want to return the 'k'th item
Output:
The 'k'th happy string of length 'n'
Constraints:
Only choose letters from {a,b,c}