Skip to content

Commit a0de20f

Browse files
committed
Minor Improvements.
1 parent 3a16191 commit a0de20f

7 files changed

Lines changed: 18 additions & 9 deletions

File tree

python/dynamic/bitonicsequence.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def longest_bitonic(sequence):
3535
decreasing_sequence[i] = max(decreasing_sequence[i], decreasing_sequence[j] + 1)
3636

3737
max_value = 0
38+
3839
for i in range(len(sequence)):
3940
bitonic_sequence_length = increasing_sequence[i] + decreasing_sequence[i] - 1
4041
max_value = max(max_value, bitonic_sequence_length)

python/dynamic/boxstacking.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636

3737
def create_rotation(given_dimensions):
3838
"""
39-
A rotation is an order wherein length is greater than or equal to width.
39+
A rotation is an order wherein length is greater than or equal to width. Having this constraint avoids the
40+
repetition of same order, but with width and length switched.
41+
42+
For e.g (height=3, width=2, length=1) is same the same box for stacking as (height=3, width=1, length=2).
4043
4144
:param given_dimensions: Original box dimensions
4245
:return: All the possible rotations of the boxes with the condition that length >= height.
@@ -64,8 +67,9 @@ def box_stack_max_height(dimensions):
6467
for i in range(1, num_boxes):
6568
for j in range(0, i):
6669
if can_stack(boxes[i], boxes[j]):
67-
if (T[j] + boxes[i].height) > T[i]:
68-
T[i] = T[j] + boxes[i].height
70+
stacked_height = T[j] + boxes[i].height
71+
if stacked_height > T[i]:
72+
T[i] = stacked_height
6973
R[i] = j
7074

7175
max_height = max(T)

python/dynamic/breakword.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
22
Problem Statement
33
=================
4+
45
Given a string and a dictionary, split the string in to multiple words so that each word belongs to the dictionary.
56
67
Video
78
-----
8-
* https://youtu.be/WepWFGxiwRs
99
10+
* https://youtu.be/WepWFGxiwRs
1011
1112
Analysis
1213
--------

python/dynamic/coin_change_num_ways.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def coin_changing_num_ways(coins, total):
2727
for i in range(rows):
2828
for j in range(cols):
2929
if (i - 1) < 0:
30-
T[i][j] = 1
3130
continue
3231
if j < coins[i]:
3332
T[i][j] = T[i - 1][j]

python/dynamic/egg_drop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Problem Statement
33
=================
44
5-
Given a certain number of eggs and a certain number of floors, determine the minimum number of attempts
6-
required to find the egg breaking floor.
5+
Given a certain number of eggs and a certain number of floors, determine the minimum number of attempts required to find
6+
the egg breaking floor.
77
88
Analysis
99
--------

python/dynamic/longest_increasing_subsequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=================
44
55
Find a subsequence in given array in which the subsequence's elements are in sorted order, lowest to highest, and in
6-
which the subsequence is as long as possible
6+
which the subsequence is as long as possible.
77
88
Video
99
-----
@@ -14,7 +14,7 @@
1414
1515
Dynamic Programming is used to solve this question. DP equation is.::
1616
17-
if(arr[i] > arr[j]) { T[i] = max(T[i], T[j] + 1 }
17+
if(arr[i] > arr[j]) { T[i] = max(T[i], T[j] + 1) }
1818
1919
* Time complexity is O(n^2).
2020
* Space complexity is O(n)

python/graph/dijkstrashortestpath.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#dijkstra's algorithm
2+
23
# java code https://github.com/mission-peace/interview/blob/master/src/com/interview/graph/DijkstraShortestPath.java
4+
35
from priorityqueue import PriorityQueue
46
from graph import Graph
57
import sys
68

9+
710
def shortest_path(graph, sourceVertex):
811

912
min_heap = PriorityQueue(True)
@@ -36,6 +39,7 @@ def shortest_path(graph, sourceVertex):
3639

3740
return distance
3841

42+
3943
def get_other_vertex_for_edge(vertex, edge):
4044
if edge.vertex1.id == vertex.id:
4145
return edge.vertex2

0 commit comments

Comments
 (0)