Skip to content

Commit 3b0292d

Browse files
Meto TrajkovskiMeto Trajkovski
authored andcommitted
Changes in testings and other small changes
1 parent 5d22213 commit 3b0292d

File tree

11 files changed

+66
-51
lines changed

11 files changed

+66
-51
lines changed

Arrays/count_triplets_with_sum_k.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ def count_triplets_2(arr, k):
7373

7474
# Test 1
7575
# Correct result => 1
76-
print(count_triplets_1([10, 11, 16, 18, 19], 40))
77-
print(count_triplets_2([10, 11, 16, 18, 19], 40))
76+
arr = [10, 11, 16, 18, 19]
77+
k = 40
78+
print(count_triplets_1(arr, k))
79+
print(count_triplets_2(arr, k))
7880

7981
# Test 2
8082
# Correct result => 2
81-
print(count_triplets_1([1, 2, 3, 4, 5], 9))
82-
print(count_triplets_2([1, 2, 3, 4, 5], 9))
83+
arr = [1, 2, 3, 4, 5]
84+
k = 9
85+
print(count_triplets_1(arr, k))
86+
print(count_triplets_2(arr, k))

Arrays/majority_element.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ def majority_element_3(nums):
8181

8282
# Test 1
8383
# Correct result => 3
84-
print(majority_element_1([3, 2, 3]))
85-
print(majority_element_2([3, 2, 3]))
86-
print(majority_element_3([3, 2, 3]))
84+
arr = [3, 2, 3]
85+
print(majority_element_1(arr))
86+
print(majority_element_2(arr))
87+
print(majority_element_3(arr))
8788

8889
# Test 2
8990
# Correct result => 2
90-
print(majority_element_1([2, 2, 1, 1, 1, 2, 2]))
91-
print(majority_element_2([2, 2, 1, 1, 1, 2, 2]))
92-
print(majority_element_3([2, 2, 1, 1, 1, 2, 2]))
91+
arr = [2, 2, 1, 1, 1, 2, 2]
92+
print(majority_element_1(arr))
93+
print(majority_element_2(arr))
94+
print(majority_element_3(arr))

Arrays/reverse_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
99
=========================================
1010
Reverse the whole array by swapping pair letters in-place (first with last, second with second from the end, etc).
11-
Exist 2 more "Pythonic" ways of reversing strings/arrays:
12-
- reversed_str = reversed(str)
13-
- reversed_str = str[::-1]
11+
Exist 2 more "Pythonic" ways of reversing arrays/strings:
12+
- reversed_arr = reversed(arr)
13+
- reversed_arr = arr[::-1]
1414
But I wanted to show how to implement a reverse algorithm step by step so someone will know how to implement it in other languages.
1515
Time Complexity: O(N)
1616
Space Complexity: O(1)

Arrays/reverse_ascending_sublists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Output explanation: 5, 7, 10 => 10, 7, 5 ; 4 => 4; 2, 7, 8 => 8, 7, 2; 1, 3 => 3, 1
1010
1111
=========================================
12-
Solution explanation
12+
Find the start and end of each sublist and reverse it in-place.
1313
Time Complexity: O(N)
1414
Space Complexity: O(1)
1515
'''

Dynamic Programming/coin_change.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ def coin_change_2(coins, amount):
8181

8282
# Test 1
8383
# Correct result => 3
84-
print(coin_change_1([1, 2, 5], 11))
85-
print(coin_change_2([1, 2, 5], 11))
84+
coins = [1, 2, 5]
85+
amount = 11
86+
print(coin_change_1(coins, amount))
87+
print(coin_change_2(coins, amount))
8688

8789
# Test 2
8890
# Correct result => -1
89-
print(coin_change_1([2], 3))
90-
print(coin_change_2([2], 3))
91+
coins = [2]
92+
amount = 3
93+
print(coin_change_1(coins, amount))
94+
print(coin_change_2(coins, amount))

Dynamic Programming/interleaving_strings.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ def interleaving_strings_2(A, B, C):
9999

100100
# Test 1
101101
# Correct result => 2
102-
print(interleaving_strings_1('xy', 'xz', 'xxyz'))
103-
104-
# Test 2
105-
# Correct result => 2
106-
print(interleaving_strings_2('xy', 'xz', 'xxyz'))
102+
a, b, c = 'xy', 'xz', 'xxyz'
103+
print(interleaving_strings_1(a, b, c))
104+
print(interleaving_strings_2(a, b, c))

Dynamic Programming/max_subarray_sum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def max_subarray_sum(a):
5353

5454
# Test 4
5555
# Correct result => 0
56-
print(max_subarray_sum([-6, -1]))
56+
print(max_subarray_sum([-6, -1]))

Linked Lists/reverse_ll.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
Solution 2: Same approach using recursion.
1414
Time Complexity: O(N)
1515
Space Complexity: O(N) , because of the recursion stack (the stack will be with N depth till the last node of the linked list is reached)
16-
1716
'''
1817

1918

Math/unique_paths.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ def unique_paths(n, m):
5454

5555
# Test 1
5656
# Correct result => 924
57-
print(unique_paths(7, 7))
58-
print(unique_paths_dp(7, 7))
57+
n, m = 7, 7
58+
print(unique_paths(n, m))
59+
print(unique_paths_dp(n, m))
5960

6061
# Test 2
6162
# Correct result => 28
62-
print(unique_paths(7, 3))
63-
print(unique_paths_dp(7, 3))
63+
n, m = 7, 3
64+
print(unique_paths(n, m))
65+
print(unique_paths_dp(n, m))
6466

6567
# Test 3
6668
# Correct result => 28
67-
print(unique_paths(3, 7))
68-
print(unique_paths_dp(3, 7))
69+
n, m = 3, 7
70+
print(unique_paths(n, m))
71+
print(unique_paths_dp(n, m))

Other/nth_fibonacci_number.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,22 @@ def nth_fibonacci_7(n):
209209

210210
# Test 1
211211
# Correct result => 21
212-
print(nth_fibonacci_1(8))
213-
print(nth_fibonacci_2(8))
214-
print(nth_fibonacci_3(8))
215-
print(nth_fibonacci_4(8))
216-
print(nth_fibonacci_5(8))
217-
print(nth_fibonacci_6(8))
218-
print(nth_fibonacci_7(8))
212+
n = 8
213+
print(nth_fibonacci_1(n))
214+
print(nth_fibonacci_2(n))
215+
print(nth_fibonacci_3(n))
216+
print(nth_fibonacci_4(n))
217+
print(nth_fibonacci_5(n))
218+
print(nth_fibonacci_6(n))
219+
print(nth_fibonacci_7(n))
219220

220221
# Test 2
221222
# Correct result => 10946
222-
print(nth_fibonacci_1(21))
223-
print(nth_fibonacci_2(21))
224-
print(nth_fibonacci_3(21))
225-
print(nth_fibonacci_4(21))
226-
print(nth_fibonacci_5(21))
227-
print(nth_fibonacci_6(21))
228-
print(nth_fibonacci_7(21))
223+
n = 21
224+
print(nth_fibonacci_1(n))
225+
print(nth_fibonacci_2(n))
226+
print(nth_fibonacci_3(n))
227+
print(nth_fibonacci_4(n))
228+
print(nth_fibonacci_5(n))
229+
print(nth_fibonacci_6(n))
230+
print(nth_fibonacci_7(n))

0 commit comments

Comments
 (0)