GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added 2 more training sites and added comments about reversing string… · code3002/coding-problems@5d22213

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Arrays
    • reverse_array.py
  • Other
    • nth_fibonacci_number.py
  • README.md
  • Strings
    • reverse_string.py
    • reverse_vowels.py
    • reverse_words_in_sentence.py
    • swap_first_and_last_word.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Arrays/reverse_array.py‎

Copy file name to clipboardExpand all lines: Arrays/reverse_array.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
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]
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.
1115
Time Complexity: O(N)
1216
Space Complexity: O(1)
1317
'''
Collapse file

‎Other/nth_fibonacci_number.py‎

Copy file name to clipboardExpand all lines: Other/nth_fibonacci_number.py
+4-50Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,10 @@ def matrix_mult(a, b):
131131
The result of multiplication is saved in 'a' (because of that, the reference
132132
shouldn't be changed, only change the values after all computations are completed
133133
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]
134137
'''
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-
143138
a00, a01 = a[0]
144139
a10, a11 = a[1]
145140
b00, b01 = b[0]
@@ -222,7 +217,6 @@ def nth_fibonacci_7(n):
222217
print(nth_fibonacci_6(8))
223218
print(nth_fibonacci_7(8))
224219

225-
226220
# Test 2
227221
# Correct result => 10946
228222
print(nth_fibonacci_1(21))
@@ -231,44 +225,4 @@ def nth_fibonacci_7(n):
231225
print(nth_fibonacci_4(21))
232226
print(nth_fibonacci_5(21))
233227
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

‎README.md‎

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 numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ If the problems from [LeetCode](https://leetcode.com/) are not enough and you ne
157157
- [PEG](https://wcipeg.com/)
158158
- [Online Judge](https://onlinejudge.org/)
159159
- [E-Olymp](https://www.e-olymp.com/en/)
160+
- [VJudge](https://vjudge.net/)
160161
- [USA CO](http://www.usaco.org/)
161162
- [CodeAbbey](http://codeabbey.com/)
162163
- [CS Academy](https://csacademy.com/)
@@ -176,6 +177,7 @@ If the problems from [LeetCode](https://leetcode.com/) are not enough and you ne
176177
- [Exercism](https://exercism.io/)
177178
- [CodeFu](https://codefu.mk/)
178179
- [Mendo](https://mendo.mk/Welcome.do)
180+
- [Z-Training](http://www.codah.club/)
179181
- [Edabit](https://edabit.com/)
180182
- [Cyber-dojo](https://cyber-dojo.org/)
181183
- [CodeKata](http://codekata.com/)
Collapse file

‎Strings/reverse_string.py‎

Copy file name to clipboardExpand all lines: Strings/reverse_string.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
=========================================
1313
Reverse the whole sentence by swapping pair letters in-place (first with last, second with second from the end, etc).
1414
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.
1620
Time Complexity: O(N)
1721
Space Complexity: O(N)
1822
'''
Collapse file

‎Strings/reverse_vowels.py‎

Copy file name to clipboardExpand all lines: Strings/reverse_vowels.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
=========================================
1212
Simple solution, find a vowel from left and swap it with a vowel from right.
1313
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).
1515
Time Complexity: O(N)
1616
Space Complexity: O(N)
1717
'''
Collapse file

‎Strings/reverse_words_in_sentence.py‎

Copy file name to clipboardExpand all lines: Strings/reverse_words_in_sentence.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
after all words are reversed, reverse the whole sentence (in place, by swapping the letters)
1515
and the first word will be last and will be in the original form.
1616
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).
1818
Time Complexity: O(N)
1919
Space Complexity: O(N)
2020
'''
Collapse file

‎Strings/swap_first_and_last_word.py‎

Copy file name to clipboardExpand all lines: Strings/swap_first_and_last_word.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Reverse the whole string, after that reverse only first and only last word,
1212
in the end reverse everything between first and last word. (using IN-PLACE reversing)
1313
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).
1515
Time complexity: O(N) , O(N + N) = O(2 * N) = O(N)
1616
Space Complexity: O(N)
1717
'''

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.