Skip to content

Commit 2ee35b6

Browse files
Chris WuChris Wu
Chris Wu
authored and
Chris Wu
committed
readme update, odd-even-jump.py
1 parent fd49745 commit 2ee35b6

File tree

2 files changed

+97
-7
lines changed

2 files changed

+97
-7
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ https://github.com/wuduhren/leetcode-python
88

99
3. The question is at `https://leetcode.com/problems/the-file-name/`. For example, `merge-sorted-array.py`'s question is at `https://leetcode.com/problems/merge-sorted-array/`.
1010

11-
# Really Great Resources
11+
# Resources
12+
These are the interview resources I personally used and only if it is really helpful I will put it here.
1213
## System Design
14+
More resource
1315
<https://github.com/shashank88/system_design>
16+
Architecture 101
17+
<https://engineering.videoblocks.com/web-architecture-101-a3224e126947>
18+
How to scale up? There are also lots of tech interview related topic in his channel.
19+
<https://www.youtube.com/watch?v=yPF94QiI2qk&t=385s>
1420

1521
## Data Structure and Algorithm
1622
Basic data structure and algorithm online course taught in Python. This course is design to help you find job and do well in the interview.
1723
<https://classroom.udacity.com/courses/ud513>
1824

19-
## Architecture 101
20-
<https://engineering.videoblocks.com/web-architecture-101-a3224e126947>
25+
##How to Prepare in a Structured Way
26+
<https://www.quora.com/How-should-I-prepare-for-my-Google-interview-if-I-have-1-month-left-and-I%E2%80%99m-applying-for-a-software-engineer-role/answer/Anthony-D-Mays?ch=10&share=5c488000&srid=W0jqp>
27+
<https://www.quora.com/How-can-I-get-a-job-at-Facebook-or-Google-in-6-months-I-need-a-concise-work-plan-to-build-a-good-enough-skill-set-Should-I-join-some-other-start-up-or-build-my-own-projects-start-up-Should-I-just-focus-on-practicing-data-structures-and-algorithms/answer/Jimmy-Saade>
28+
<https://www.quora.com/What-should-I-know-from-the-CLRS-3rd-edition-book-if-my-aim-is-to-get-into-Google/answer/Jimmy-Saade>
2129

2230
## Overall Mindset
2331
This is a speech from Sean Lee on "How to Get a Job at the Big 4". I highly recommend this because it gives me the right mindset on how to put in the work.
@@ -26,10 +34,6 @@ This is a speech from Sean Lee on "How to Get a Job at the Big 4". I highly reco
2634
CS DoJo on "How I Got a Job at Google as a Software Engineer". There are also lots of technique on coding interview in his channel.
2735
<https://www.youtube.com/watch?v=UPO-9iMjBpc>
2836

29-
## How to scale up
30-
There are also lots of tech interview related topic in his channel.
31-
<https://www.youtube.com/watch?v=yPF94QiI2qk&t=385s>
32-
3337
## Interview Question Survey
3438
<https://www.glassdoor.com/index.htm>
3539
<https://www.careercup.com/>

odd-even-jump.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
class Solution(object):
2+
def oddEvenJumps(self, A):
3+
l = len(A)
4+
odd_jump = [-1]*l #odd_jump[i], when odd jump from index i, what index it is going to land
5+
even_jump = [-1]*l #even_jump[i], when even jump from index i, what index it is going to land
6+
7+
odd = [False]*l #odd[i], can index i, starting by odd jump, go to the end
8+
even = [False]*l #even[i], can index i, starting by even jump, go to the end
9+
odd[-1] = True
10+
even[-1] = True
11+
12+
#construct odd_jump
13+
stack = []
14+
for n, i in sorted((n, i) for i, n in enumerate(A)):
15+
while stack and stack[-1]<i:
16+
odd_jump[stack.pop()] = i
17+
stack.append(i)
18+
19+
#construct even_jump
20+
stack = []
21+
for n, i in sorted((-n, i) for i, n in enumerate(A)):
22+
while stack and stack[-1]<i:
23+
even_jump[stack.pop()] = i
24+
stack.append(i)
25+
26+
for i in reversed(xrange(l-1)):
27+
if odd_jump[i]!=-1:
28+
odd[i] = even[odd_jump[i]]
29+
if even_jump[i]!=-1:
30+
even[i] = odd[even_jump[i]]
31+
32+
return sum(odd)
33+
34+
# Naive Approach
35+
class Solution(object):
36+
def oddEvenJumps(self, A):
37+
def jump(start, odd):
38+
curr = None
39+
40+
if odd:
41+
temp.add(start)
42+
43+
n = float('inf')
44+
for i in xrange(start+1, len(A)):
45+
val = A[i]
46+
if i not in visited and val>=A[start] and val<n:
47+
n = val
48+
curr = i
49+
else:
50+
n = float('-inf')
51+
for i in xrange(start+1, len(A)):
52+
val = A[i]
53+
if i not in visited and val<=A[start] and val>n:
54+
n = val
55+
curr = i
56+
return curr
57+
58+
opt = set()
59+
not_opt = set()
60+
end = len(A)-1
61+
62+
for i in xrange(len(A)):
63+
if i in opt or i in not_opt: continue
64+
65+
odd = True
66+
curr = i
67+
temp = set()
68+
visited = set()
69+
70+
temp.add(i)
71+
72+
while True:
73+
print curr
74+
visited.add(i)
75+
if curr==None:
76+
not_opt.update(temp)
77+
break
78+
if curr==end:
79+
opt.update(temp)
80+
break
81+
82+
curr = jump(curr, odd)
83+
odd = not odd
84+
85+
return len(opt)
86+

0 commit comments

Comments
 (0)