GeezerVison is showing github.com — Added 2 more training sites and added comments about reversing string… · code3002/coding-problems@5d22213
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/reverse_array.py +4Lines changed: 4 additions & 0 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] | | 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. | 11 | 15 | Time Complexity: O(N) | 12 | 16 | Space Complexity: O(1) | 13 | 17 | ''' | |
Collapse file Copy file name to clipboardExpand all lines: Other/nth_fibonacci_number.py +4-50Lines changed: 4 additions & 50 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -131,15 +131,10 @@ def matrix_mult(a, b): | 131 | 131 | The result of multiplication is saved in 'a' (because of that, the reference | 132 | 132 | shouldn't be changed, only change the values after all computations are completed | 133 | 133 | because 'b' could be the same reference/matrix as 'a'). | | 134 | + a[0] is the first row of a, which contains a[0][0], a[0][1] | | 135 | + Python "unrolls" a00, a01 = a[0], which effectively makes it: | | 136 | + a00 = a[0][0] and a01 = a[0][1] | 134 | 137 | ''' | 135 | | - | 136 | | - # We know that a is a 2x2 matrix: | 137 | | - # a[0] is the first row of a, which contains a[0][0], a[0][1] | 138 | | - # Python "unrolls" a00, a01 = a[0], | 139 | | - # which effectively makes it: | 140 | | - # a00 = a[0][0] | 141 | | - # a01 = a[0][1] | 142 | | - | 143 | 138 | a00, a01 = a[0] | 144 | 139 | a10, a11 = a[1] | 145 | 140 | b00, b01 = b[0] | @@ -222,7 +217,6 @@ def nth_fibonacci_7(n): | 222 | 217 | print(nth_fibonacci_6(8)) | 223 | 218 | print(nth_fibonacci_7(8)) | 224 | 219 |
| 225 | | - | 226 | 220 | # Test 2 | 227 | 221 | # Correct result => 10946 | 228 | 222 | print(nth_fibonacci_1(21)) | @@ -231,44 +225,4 @@ def nth_fibonacci_7(n): | 231 | 225 | print(nth_fibonacci_4(21)) | 232 | 226 | print(nth_fibonacci_5(21)) | 233 | 227 | print(nth_fibonacci_6(21)) | 234 | | -print(nth_fibonacci_7(21)) | 235 | | - | 236 | | -from timeit import default_timer | 237 | | -# Comparision of how long each method takes: | 238 | | -iters = 100 | 239 | | -num = 25 | 240 | | -start = default_timer() | 241 | | -for _ in range(iters): | 242 | | - nth_fibonacci_1(num) | 243 | | -end = default_timer() - start | 244 | | -print("nth_fibonacci_1 took %fs" % end) | 245 | | -start = default_timer() | 246 | | -for _ in range(iters): | 247 | | - nth_fibonacci_2(num) | 248 | | -end = default_timer() - start | 249 | | -print("nth_fibonacci_2 took %fs" % end) | 250 | | -start = default_timer() | 251 | | -for _ in range(iters): | 252 | | - nth_fibonacci_3(num) | 253 | | -end = default_timer() - start | 254 | | -print("nth_fibonacci_3 took %fs" % end) | 255 | | -start = default_timer() | 256 | | -for _ in range(iters): | 257 | | - nth_fibonacci_4(num) | 258 | | -end = default_timer() - start | 259 | | -print("nth_fibonacci_4 took %fs" % end) | 260 | | -start = default_timer() | 261 | | -for _ in range(iters): | 262 | | - nth_fibonacci_5(num) | 263 | | -end = default_timer() - start | 264 | | -print("nth_fibonacci_5 took %fs" % end) | 265 | | -for _ in range(iters): | 266 | | - nth_fibonacci_6(num) | 267 | | -end = default_timer() - start | 268 | | -print("nth_fibonacci_6 took %fs" % end) | 269 | | -start = default_timer() | 270 | | -for _ in range(iters): | 271 | | - nth_fibonacci_7(num) | 272 | | -end = default_timer() - start | 273 | | -print("nth_fibonacci_7 took %fs" % end) | 274 | | - | | 228 | +print(nth_fibonacci_7(21)) |
Collapse file Copy file name to clipboardExpand all lines: README.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -157,6 +157,7 @@ If the problems from [LeetCode](https://leetcode.com/) are not enough and you ne | 157 | 157 | - [PEG](https://wcipeg.com/) | 158 | 158 | - [Online Judge](https://onlinejudge.org/) | 159 | 159 | - [E-Olymp](https://www.e-olymp.com/en/) | | 160 | +- [VJudge](https://vjudge.net/) | 160 | 161 | - [USA CO](http://www.usaco.org/) | 161 | 162 | - [CodeAbbey](http://codeabbey.com/) | 162 | 163 | - [CS Academy](https://csacademy.com/) | @@ -176,6 +177,7 @@ If the problems from [LeetCode](https://leetcode.com/) are not enough and you ne | 176 | 177 | - [Exercism](https://exercism.io/) | 177 | 178 | - [CodeFu](https://codefu.mk/) | 178 | 179 | - [Mendo](https://mendo.mk/Welcome.do) | | 180 | +- [Z-Training](http://www.codah.club/) | 179 | 181 | - [Edabit](https://edabit.com/) | 180 | 182 | - [Cyber-dojo](https://cyber-dojo.org/) | 181 | 183 | - [CodeKata](http://codekata.com/) | |
Collapse file Copy file name to clipboardExpand all lines: Strings/reverse_string.py +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | ========================================= | 13 | 13 | Reverse the whole sentence by swapping pair letters in-place (first with last, second with second from the end, etc). | 14 | 14 | In Python, the string manipulation operations are too slow (string is immutable), because of that we need to convert the string into array. | 15 | | -In C/C++, the Space complexity will be O(1). | | 15 | +In C/C++, the Space complexity will be O(1) (because the strings are just arrays with chars). | | 16 | +Exist 2 more "Pythonic" ways of reversing strings/arrays: | | 17 | +- reversed_str = reversed(str) | | 18 | +- reversed_str = str[::-1] | | 19 | +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. | 16 | 20 | Time Complexity: O(N) | 17 | 21 | Space Complexity: O(N) | 18 | 22 | ''' | |
Collapse file Copy file name to clipboardExpand all lines: Strings/reverse_vowels.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | ========================================= | 12 | 12 | Simple solution, find a vowel from left and swap it with a vowel from right. | 13 | 13 | In Python, the string manipulation operations are too slow (string is immutable), because of that we need to convert the string into array. | 14 | | -In C/C++, the Space complexity will be O(1). | | 14 | +In C/C++, the Space complexity will be O(1) (because the strings are just arrays with chars). | 15 | 15 | Time Complexity: O(N) | 16 | 16 | Space Complexity: O(N) | 17 | 17 | ''' | |
Collapse file Copy file name to clipboardExpand all lines: Strings/reverse_words_in_sentence.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 | after all words are reversed, reverse the whole sentence (in place, by swapping the letters) | 15 | 15 | and the first word will be last and will be in the original form. | 16 | 16 | In Python, the string manipulation operations are too slow (string is immutable), because of that we need to convert the string into array. | 17 | | -In C/C++, the Space complexity will be O(1). | | 17 | +In C/C++, the Space complexity will be O(1) (because the strings are just arrays with chars). | 18 | 18 | Time Complexity: O(N) | 19 | 19 | Space Complexity: O(N) | 20 | 20 | ''' | |
Collapse file Copy file name to clipboardExpand all lines: Strings/swap_first_and_last_word.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | Reverse the whole string, after that reverse only first and only last word, | 12 | 12 | in the end reverse everything between first and last word. (using IN-PLACE reversing) | 13 | 13 | In Python, the string manipulation operations are too slow (string is immutable), because of that we need to convert the string into array. | 14 | | -In C/C++, the Space complexity will be O(1). | | 14 | +In C/C++, the Space complexity will be O(1) (because the strings are just arrays with chars). | 15 | 15 | Time complexity: O(N) , O(N + N) = O(2 * N) = O(N) | 16 | 16 | Space Complexity: O(N) | 17 | 17 | ''' | |
|