Skip to content

Commit c7db951

Browse files
committed
Add 662 and intuit screen
1 parent d677b5c commit c7db951

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

2024/intuit/screen.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Leetcode 1. Two Sum
2+
# Follow up: 167. Two Sum II - Input Array Is Sorted
3+
4+
# Resume deepdive
5+
6+
# What's the difference between "==" and "==="?
7+
# React vs. Vue
8+
# How to share states between two components? Promote state to parent component, useContext/useReducer
9+
# How many React hooks do you know?
10+
# What does useMemo hook do?

2024/tiktok/July-interview.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22

3-
# There are N buckets of apples. We would like to collect K apples from a row of continuous buckets.
4-
# Write a function that returns the first buckets combo that would fulfil the requirement.
3+
# There are N buckets of apples. Each bucket contains a certain amount of apples designated by an integer buckets[i].
4+
# We would like to collect K apples from a row of continuous buckets.
5+
# Write a function that returns the first buckets combo that would fulfil the requirement.
56
# If there is no valid buckets, return []
67
# Example 1:
78
# Apples in buckets: [2, 3, 4, 5, 6, 2, 3]
@@ -48,7 +49,7 @@ def solution(k, buckets):
4849
# How to implement a triangle down arrow CSS? Use border
4950
# What is the box model in CSS?
5051
# Use JS to sort a list of version number: ["1.21.0","1.2.1","1.2.0","1.1.1","1.1.0","1.0.1","1.0.0"]. The version number could contain invalid characters
51-
52+
# Generate Subset
5253
# Final round (HM)
5354
class Solution:
5455
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def widthOfBinaryTree(self, root: Optional[TreeNode]) -> int:
9+
"""
10+
Using recursive dfs method, label each node using heap index (so that null node still occupies one position)
11+
Have a global hashmap storing level => (leftmost pos, rightmost pos)
12+
result is max(rightmost - leftmost) + 1, since the level width includes both leftmost node and rightmost node
13+
e.g.
14+
1 <-- root
15+
2 3 <-- second level
16+
4 5 6 7 <-- third level
17+
"""
18+
levelinfo = {}
19+
res = float('-inf')
20+
21+
def dfs(node, level, pos):
22+
nonlocal res, levelinfo
23+
if not node:
24+
return
25+
if level not in levelinfo:
26+
levelinfo[level] = [pos, pos]
27+
28+
levelinfo[level][0] = min(levelinfo[level][0], pos)
29+
levelinfo[level][1] = max(levelinfo[level][1], pos)
30+
res = max(res, levelinfo[level][1]-levelinfo[level][0])
31+
32+
dfs(node.left, level+1, pos*2+1)
33+
dfs(node.right, level+1, pos*2+2)
34+
dfs(root, 0, 0)
35+
return res+1

0 commit comments

Comments
 (0)