GeezerVison is showing github.com — Changes in testings and other small changes · Pranshu-Raj/coding-problems@3b0292d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Arrays/count_triplets_with_sum_k.py +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,10 +73,14 @@ def count_triplets_2(arr, k): | 73 | 73 |
| 74 | 74 | # Test 1 | 75 | 75 | # 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)) | 78 | 80 |
| 79 | 81 | # Test 2 | 80 | 82 | # 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)) |
Collapse file Copy file name to clipboardExpand all lines: Arrays/majority_element.py +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,12 +81,14 @@ def majority_element_3(nums): | 81 | 81 |
| 82 | 82 | # Test 1 | 83 | 83 | # 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)) | 87 | 88 |
| 88 | 89 | # Test 2 | 89 | 90 | # 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)) |
Collapse file Copy file name to clipboardExpand all lines: Arrays/reverse_array.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 |
| 9 | 9 | ========================================= | 10 | 10 | 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] | 14 | 14 | 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. | 15 | 15 | Time Complexity: O(N) | 16 | 16 | Space Complexity: O(1) | |
Collapse file Copy file name to clipboardExpand all lines: Arrays/reverse_ascending_sublists.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | Output explanation: 5, 7, 10 => 10, 7, 5 ; 4 => 4; 2, 7, 8 => 8, 7, 2; 1, 3 => 3, 1 | 10 | 10 |
| 11 | 11 | ========================================= | 12 | | -Solution explanation | | 12 | +Find the start and end of each sublist and reverse it in-place. | 13 | 13 | Time Complexity: O(N) | 14 | 14 | Space Complexity: O(1) | 15 | 15 | ''' | |
Collapse file Copy file name to clipboardExpand all lines: Dynamic Programming/coin_change.py +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,10 +81,14 @@ def coin_change_2(coins, amount): | 81 | 81 |
| 82 | 82 | # Test 1 | 83 | 83 | # 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)) | 86 | 88 |
| 87 | 89 | # Test 2 | 88 | 90 | # 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)) |
Collapse file Copy file name to clipboardExpand all lines: Dynamic Programming/interleaving_strings.py +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,8 +99,6 @@ def interleaving_strings_2(A, B, C): | 99 | 99 |
| 100 | 100 | # Test 1 | 101 | 101 | # 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)) |
Collapse file Copy file name to clipboardExpand all lines: Dynamic Programming/max_subarray_sum.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,4 +53,4 @@ def max_subarray_sum(a): | 53 | 53 |
| 54 | 54 | # Test 4 | 55 | 55 | # Correct result => 0 | 56 | | -print(max_subarray_sum([-6, -1])) | | 56 | +print(max_subarray_sum([-6, -1])) |
Collapse file Copy file name to clipboardExpand all lines: Linked Lists/reverse_ll.py -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | Solution 2: Same approach using recursion. | 14 | 14 | Time Complexity: O(N) | 15 | 15 | 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 | | -
| 17 | 16 | ''' | 18 | 17 |
| 19 | 18 |
| |
Collapse file Copy file name to clipboardExpand all lines: Math/unique_paths.py +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,15 +54,18 @@ def unique_paths(n, m): | 54 | 54 |
| 55 | 55 | # Test 1 | 56 | 56 | # 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)) | 59 | 60 |
| 60 | 61 | # Test 2 | 61 | 62 | # 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)) | 64 | 66 |
| 65 | 67 | # Test 3 | 66 | 68 | # 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)) |
Collapse file Copy file name to clipboardExpand all lines: Other/nth_fibonacci_number.py +16-14Lines changed: 16 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -209,20 +209,22 @@ def nth_fibonacci_7(n): | 209 | 209 |
| 210 | 210 | # Test 1 | 211 | 211 | # 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)) | 219 | 220 |
| 220 | 221 | # Test 2 | 221 | 222 | # 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)) |
|