Skip to content

Commit 54efde1

Browse files
committed
Adding solutions for Tasks Before Session 6
1 parent 88ff6f4 commit 54efde1

6 files changed

+64
-0
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,16 @@ And here's a GIF of my updated InterviewBit Graphs topic page:
193193
* [GIF of my updated InterviewBit Graphs topic page](https://github.com/tachyonlabs/CodePath-Alumni-Professional-Interview-Prep-Course/blob/master/interviewbit-graphs-topics-2.gif)
194194

195195
I took the "CodePath Interview Prep - Unit 5" test on January 28, so you should have received it.
196+
197+
## Tasks Before Session 6
198+
199+
I've done four Dynamic Programming problems on InterviewBit so far:
200+
201+
* Stairs
202+
* Jump Game Array
203+
* Min Sum Path in Matrix
204+
* Min Sum Path in Triangle
205+
206+
And here's a GIF of my InterviewBit Dynamic Programming topic page:
207+
208+
* GIF of my InterviewBit Dynamic Programming topic page
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
# @param A : list of integers
3+
# @return an integer
4+
def canJump(self, A):
5+
min_possible = len(A) - 1
6+
for i in range(len(A) - 1, -1, -1):
7+
if A[i] >= min_possible - i:
8+
min_possible = i
9+
if min_possible == 0:
10+
return 1
11+
12+
return 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
# @param A : list of list of integers
3+
# @return an integer
4+
def minPathSum(self, A):
5+
for r in range(len(A) - 1, -1, -1):
6+
for c in range(len(A[0]) - 1, -1, -1):
7+
if r < len(A) - 1 and c < len(A[0]) - 1:
8+
A[r][c] += min(A[r + 1][c], A[r][c + 1])
9+
elif r < len(A) - 1:
10+
A[r][c] += A[r + 1][c]
11+
elif c < len(A[0]) - 1:
12+
A[r][c] += A[r][c + 1]
13+
14+
return A[0][0]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
# @param A : list of list of integers
3+
# @return an integer
4+
def minimumTotal(self, A):
5+
if len(A) == 1:
6+
return A[0][0]
7+
8+
print A
9+
for r in range(len(A) - 2, -1, -1):
10+
for c in range(len(A[r])):
11+
A[r][c] += min(A[r + 1][c], A[r + 1][c + 1])
12+
print A
13+
14+
return A[0]
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
# @param A : integer
3+
# @return an integer
4+
def __init__(self):
5+
self.fibs = [0, 1]
6+
7+
def climbStairs(self, A):
8+
while A >= len(self.fibs) - 2:
9+
self.fibs.append(self.fibs[-1] + self.fibs[-2])
10+
11+
return self.fibs[A + 1]
6.78 MB
Loading

0 commit comments

Comments
 (0)