diff --git a/.DS_Store b/.DS_Store index 26c6c63..039307e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/1_Course-Introduction.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/1_Course-Introduction.md new file mode 100644 index 0000000..39056b6 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/1_Course-Introduction.md @@ -0,0 +1,11 @@ +# 1. Course Introduction + + + +## Resources for this lecture + + + +--- + +[Previous]() | [Next](./2_Full-Course-Curriculum-Overview.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/2_Full-Course-Curriculum-Overview.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/2_Full-Course-Curriculum-Overview.md new file mode 100644 index 0000000..d924ec8 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/2_Full-Course-Curriculum-Overview.md @@ -0,0 +1,10 @@ +# 2. Full Course Curriculum Overview + + +## Resources for this lecture + + + +--- + +[Previous](./1_Course-Introduction.md) | [Next](./3_How-to-get-help-for-the-Course.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/38_Algorithm-Analysis-and-Big-O-Section-Overview.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/38_Algorithm-Analysis-and-Big-O-Section-Overview.md new file mode 100644 index 0000000..ee7180c --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/38_Algorithm-Analysis-and-Big-O-Section-Overview.md @@ -0,0 +1,23 @@ +# 38. Algorithm Analysis and Big O Section Overview + +
+ Slides: Algorithm Analysis and Big O Section Overview + +

+ + + +

+ +
+ + +## Resources for this lecture + +- [Python-for-Algorithms--Data-Structures--and-Interviews-master.zip](https://python-ds.s3.us-west-1.amazonaws.com/Python-for-Data-Structures-Algorithms-and-Interviews/Resources/Python-for-Algorithms--Data-Structures--and-Interviews-master.zip) + +- [https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews) + +--- + +[Previous](./4_Course-FAQ.md) | [Next](./39_Introduction-to-Algorithm-Analysis-and-Big-O.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/39_Introduction-to-Algorithm-Analysis-and-Big-O.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/39_Introduction-to-Algorithm-Analysis-and-Big-O.md new file mode 100644 index 0000000..97172d6 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/39_Introduction-to-Algorithm-Analysis-and-Big-O.md @@ -0,0 +1,85 @@ +# 39. Introduction to Algorithm Analysis and Big O + +
+ Slides: Introduction to Algorithm Analysis and Big O + +

+ + + + + +

+ +
+ +
+ Result: picture capture + +- `01-intro-analysis-big-o.py` + +```python +import timeit + +# First function (Note the use of range since this is in Python 3) +def sum1(n): + ''' + Take an input of n and return the sum of the numbers from 0 to n + ''' + final_sum = 0 + for x in range(n+1): + final_sum += x + + return final_sum + +print(sum1(10)) + +timer1 = timeit.Timer('sum1(10)', globals=globals()) + +time_taken1 = timer1.timeit(number=1000) + +print(f"Time taken by sum1: {time_taken1:.6f} seconds") + +def sum2(n): + """ + Take an input of n and return the sum of the numbers from 0 to n + """ + return (n*(n+1))/2 + +print(sum2(10)) + +timer2 = timeit.Timer('sum2(10)', globals=globals()) + +time_taken2 = timer2.timeit(number=1000) + +print(f"Time taken by sum2: {time_taken2:.6f} seconds") + +``` + +- run `python3 01-intro-analysis-big-o.py` + +```bash +55 +Time taken by sum1: 0.000760 seconds +55.0 +Time taken by sum2: 0.000153 seconds +``` + +
+ +
+ Codebase: + +- [01-intro-analysis-big-o.py](../../codebase/python-ds-interview/01-intro-big-o/01-intro-analysis-big-o.py) + +- [01-Introduction to Algorithm Analysis and Big O .ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/01-Algorithm%20Analysis%20and%20Big%20O/01-Introduction%20to%20Algorithm%20Analysis%20and%20Big%20O%20.ipynb) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./38_Algorithm-Analysis-and-Big-O-Section-Overview.md) | [Next](./40_Big-O-Notation.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/3_How-to-get-help-for-the-Course.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/3_How-to-get-help-for-the-Course.md new file mode 100644 index 0000000..f6de778 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/3_How-to-get-help-for-the-Course.md @@ -0,0 +1,65 @@ +# 3. How to get help for the Course! + +GUIDE TO GETTING HELP FOR THE COURSE + +Hey everyone, here are some helpful tips for getting help and your questions answered as quickly as possible! + +For non-technical section questions: + +Before asking a discussion question, you should try: + +1. Searching on Google for similar questions or comments to answer what you are looking for. + +2. If you do need to post to the discussion forum , ask good questions! + +- Be Positive! Other students will be more likely to help out! + +- Be clear with your question and phrase it with a clear thought in mind. + + + +Make sure to thank people who answer your questions! + +Try to answer other people's questions to improve your own understanding! + + + +For technical section questions: + +Before asking a discussion question, you should try: + +1. Debugging your code + +- Check for error messages + +- Remove all the code you just added until it works again, and then add it in line by line + +- Compare your code against the example Jupyter Notebook, all the technical section lectures have corresponding Jupyter Notebooks (notebooks with Python code and explanatory text) available for you to download and run. Make sure your code is exactly the like the Jupyter Notebooks! + +2. Find Solutions Online + +- Google the specific error message you got along with "Python" + +- Search StackOverflow for your problem or error + +- Google "How do I...." for what you are trying to do + +3. If you do need to post to the discussion forum , ask good questions! + +- Be Positive! Other students will be more likely to help out! + +- Be specific, don't paste in a massive amount of code. Instead try posting a screenshot of the error message + +- Try linking to the code hosted somewhere else, like a gist from GitHub + +Make sure to thank people who answer your questions! + +Try to answer other people's questions to improve your own understanding! + +## Resources for this lecture + + + +--- + +[Previous](./2_Full-Course-Curriculum-Overview.md) | [Next](./4_Course-FAQ.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/40_Big-O-Notation.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/40_Big-O-Notation.md new file mode 100644 index 0000000..6c21663 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/40_Big-O-Notation.md @@ -0,0 +1,64 @@ +# 40. Big O Notation + +
+ Result: picture capture + +- `02-big-o-notion.py` + +```python +import numpy as np +import matplotlib.pyplot as plt + +# Import math module specifically for the log function +from math import log + +# Set up runtime comparisons +n = np.linspace(1, 10, 1000) +labels = ['Constant', 'Logarithmic', 'Linear', 'Log Linear', 'Quadratic', 'Cubic', 'Exponential'] +big_o = [np.ones(n.shape), np.log(n), n, n*np.log(n), n**2, n**3, 2**n] + +# Plot setup +plt.figure(figsize=(12, 10)) +plt.ylim(0, 50) + +for i in range(len(big_o)): + plt.plot(n, big_o[i], label=labels[i]) + +plt.legend(loc=0) +plt.ylabel('Relative Runtime') +plt.xlabel('n') + +fig = plt.gcf() +fig.set_size_inches(12, 4) +fig.savefig('../../../imgs/py-ds/02-big-o-notion.png', dpi=300) + +# Display the plot +plt.show() + +``` + +- run `python3 02-big-o-notion.py` + +

+ + +

+ +
+ +
+ Codebase: + +- [02-big-o-notion.py](../../codebase/python-ds-interview/01-intro-big-o/02-big-o-notion.py) + +- [02-Big O Notation.ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/01-Algorithm%20Analysis%20and%20Big%20O/02-Big%20O%20Notation.ipynb) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./39_Introduction-to-Algorithm-Analysis-and-Big-O.md) | [Next](./41_Big-O-Examples.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/41_Big-O-Examples.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/41_Big-O-Examples.md new file mode 100644 index 0000000..c9da38c --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/41_Big-O-Examples.md @@ -0,0 +1,20 @@ +# 41. Big O Examples + +
+ Codebase: + +- [03-big-o-examples.py](../../codebase/python-ds-interview/01-intro-big-o/03-big-o-examples.py) + +- [03-Big O Examples .ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/01-Algorithm%20Analysis%20and%20Big%20O/03-Big%20O%20Examples%20.ipynb) + +
+ +## Resources for this lecture + +* [Big-O Notation Explained](http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o/487278#487278) + +* [Big-O Examples Explained](http://stackoverflow.com/questions/2307283/what-does-olog-n-mean-exactly) + +--- + +[Previous](./40_Big-O-Notation.md) | [Next](./42_Homework-Reading-Asssignment.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/42_Homework-Reading-Asssignment.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/42_Homework-Reading-Asssignment.md new file mode 100644 index 0000000..3e70329 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/42_Homework-Reading-Asssignment.md @@ -0,0 +1,13 @@ +# 42. Homework Reading Asssignment + +Remember to finish the reading assignment mentioned in the last lecture before continuing so you can fully understand Big O! It's another great resource available to you! + +## Resources for this lecture + +* [Big-O Notation Explained](http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o/487278#487278) + +* [Big-O Examples Explained](http://stackoverflow.com/questions/2307283/what-does-olog-n-mean-exactly) + +--- + +[Previous](./41_Big-O-Examples.md) | [Next](./43_Big-O-for-Python-Data-Structures.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/43_Big-O-for-Python-Data-Structures.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/43_Big-O-for-Python-Data-Structures.md new file mode 100644 index 0000000..9774084 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/43_Big-O-for-Python-Data-Structures.md @@ -0,0 +1,18 @@ +# 43. Big O for Python Data Structures + +
+ Codebase: + +- [04-big-o-for-python-data-structures.py](../../codebase/python-ds-interview/01-intro-big-o/04-big-o-for-python-data-structures.py) + +- [04-Big O for Python Data Structures.ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/01-Algorithm%20Analysis%20and%20Big%20O/04-Big%20O%20for%20Python%20Data%20Structures.ipynb) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./42_Homework-Reading-Asssignment.md) | [Next](./44-Big-O-Reference-Cheat-Sheet.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/44-Big-O-Reference-Cheat-Sheet.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/44-Big-O-Reference-Cheat-Sheet.md new file mode 100644 index 0000000..3d0d340 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/44-Big-O-Reference-Cheat-Sheet.md @@ -0,0 +1,11 @@ +# 44. Big-O Reference Cheat Sheet + +Check out the link for a Cheat Sheet which covers Big-O performance for common data structures! Reference this cheat sheet once you learn about the data structure! + +## Resources for this lecture + +- [Big-O Cheat Sheet](http://bigocheatsheet.com/) + +--- + +[Previous](./43_Big-O-for-Python-Data-Structures.md) | [Next](./45_Introduction-to-Array-Based-Sequences.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/45_Introduction-to-Array-Based-Sequences.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/45_Introduction-to-Array-Based-Sequences.md new file mode 100644 index 0000000..ad1324f --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/45_Introduction-to-Array-Based-Sequences.md @@ -0,0 +1,24 @@ +# 45. Introduction to Array Based Sequences + +
+ Slides: Introduction to Array Based Sequences + +

+ + + + + + +

+ +
+ + +## Resources for this lecture + + + +--- + +[Previous](./44-Big-O-Reference-Cheat-Sheet.md) | [Next](./46_Low-Level-Arrays.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/46_Low-Level-Arrays.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/46_Low-Level-Arrays.md new file mode 100644 index 0000000..c449f00 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/46_Low-Level-Arrays.md @@ -0,0 +1,41 @@ +# 46. Low Level Arrays + +
+ Slides: Introduction to Array Based Sequences + +

+ + + + + + + + + + + + + + + + + + + + + + + +

+ +
+ + +## Resources for this lecture + + + +--- + +[Previous](./45_Introduction-to-Array-Based-Sequences.md) | [Next](./47_Dynamic-Array.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/47_Dynamic-Array.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/47_Dynamic-Array.md new file mode 100644 index 0000000..19a9cba --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/47_Dynamic-Array.md @@ -0,0 +1,81 @@ +# 47. Dynamic Array + +
+ Slides: Dynamic Array + +

+ + + + + + + + + + + +

+ +
+ +
+ Result: print or picture capture + +- `03_dynamic_array.py` + +```python +import sys + +# Set n +n = 10 + +data = [] + +for i in range(n): + + # Number of elements + a = len(data) + + # Actual size in bytes + b = sys.getsizeof(data) + + print('Length: {0:3d}; Size in bytes: {1:4d}'.format(a, b)) + + # increase length by one + data.append(n) +``` + +- run `python 03_dynamic_array.py` + +```bash +Length: 0; Size in bytes: 56 +Length: 1; Size in bytes: 88 +Length: 2; Size in bytes: 88 +Length: 3; Size in bytes: 88 +Length: 4; Size in bytes: 88 +Length: 5; Size in bytes: 120 +Length: 6; Size in bytes: 120 +Length: 7; Size in bytes: 120 +Length: 8; Size in bytes: 120 +Length: 9; Size in bytes: 184 +``` + +
+ +
+ Codebase: + +- [03_dynamic_array.py](../../codebase/python-ds-interview/02-array-sequences/03_dynamic_array.py) + +- [02-Array Sequences](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/tree/master/02-Array%20Sequences) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./46_Low-Level-Arrays.md) | [Next](./48_Dynamic-Array-Excercise.md) diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/48_Dynamic-Array-Excercise.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/48_Dynamic-Array-Excercise.md new file mode 100644 index 0000000..f0bc9c9 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/48_Dynamic-Array-Excercise.md @@ -0,0 +1,35 @@ +# 48. Dynamic Array Excercise + +
+ Study Notes: + +- [ChatGPT: How to us `ctypes` in Python?](./notes/48.1_How_to_use_ctypes_in_python.md) + +- [ChatGPT: How to use `make_array`?](./notes/48.2_How-to-use-make_array.md) + +- [ChatGPT: Why double size `in append(self, ele)`?](./notes/48.3_Why_double_size_in_append_method.md) + +- [ChatGPT: How to use `sys.getsizeof()` or `tracemalloc`?](./notes/48.4_use-sys.getsizeof()-to-estimate-the-memory-usage-by-DynamicArray.md) + +
+ +
+ Codebase: + +- [04_dynamic_array_exercise.py](../../codebase/python-ds-interview/02-array-sequences/04_dynamic_array_exercise.py) + +- [04-Dynamic Array Exercise.ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/02-Array%20Sequences/04-Dynamic%20Array%20Exercise.ipynb) + +- [ctypes and make_array](../../codebase/python-ds-interview/02-array-sequences/ctypes-make_array/) + +
+ +## Resources for this lecture + +- [ctypes — A foreign function library for Python](https://docs.python.org/3/library/ctypes.html) + + + +--- + +[Previous](./47_Dynamic-Array.md) | [Next](./49_Amortization.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/49_Amortization.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/49_Amortization.md new file mode 100644 index 0000000..7d1c8e0 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/49_Amortization.md @@ -0,0 +1,37 @@ +# 49. Amortization + +
+ Slides: Amortization + +

+ + + + + + + + + +

+ +
+ +
+ Codebase: + +- [04_dynamic_array_exercise.py](../../codebase/python-ds-interview/02-array-sequences/04_dynamic_array_exercise.py) + +- [04-Dynamic Array Exercise.ipynb](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/02-Array%20Sequences/04-Dynamic%20Array%20Exercise.ipynb) + +
+ +## Resources for this lecture + +- [Amortized Analysis](https://python-ds.s3.us-west-1.amazonaws.com/Python-for-Data-Structures-Algorithms-and-Interviews/Resources/Amortized-Analysis.pdf) + + + +--- + +[Previous](./48_Dynamic-Array-Excercise.md) | [Next](./50_Interview-Problems-Arrays.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/4_Course-FAQ.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/4_Course-FAQ.md new file mode 100644 index 0000000..ca6288f --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/4_Course-FAQ.md @@ -0,0 +1,28 @@ +# 4. Course FAQ + +**Course FAQ** + +**1. Where can I find the materials for the technical section of the course?** + +You can download them as a zip file in the resource lecture in the **Technical Break Section** of the course! + +Or you can view them online here: + +https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews + +**2. Which half of the course should I do first, Non-Technical or Technical?** + +That's up to you. If you're more than 4 months away from interviewing, just do the course in sequential order. + +If you have interviews coming up in less than a month, you might want to jump to the technical prep section, as well as overlooking the non-technical sectiosn focusing on what to do during an interview. + + +## Resources for this lecture + +- [Python-for-Algorithms--Data-Structures--and-Interviews-master.zip](https://python-ds.s3.us-west-1.amazonaws.com/Python-for-Data-Structures-Algorithms-and-Interviews/Resources/Python-for-Algorithms--Data-Structures--and-Interviews-master.zip) + +- [https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews) + +--- + +[Previous](./3_How-to-get-help-for-the-Course.md) | [Next]() diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/50_Interview-Problems-Arrays.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/50_Interview-Problems-Arrays.md new file mode 100644 index 0000000..7bd08d6 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/50_Interview-Problems-Arrays.md @@ -0,0 +1,35 @@ +# 50. Interview Problems - Arrays + +
+ Slides: Interview Problems - Arrays + +

+ + + + + + + + + +

+ +
+ +
+ Codebase: + +- [Array-Sequences-Interview-Questions](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/) + +- [Array Sequences Interview Questions](https://github.com/jmportilla/Python-for-Algorithms--Data-Structures--and-Interviews/tree/master/02-Array%20Sequences/Array%20Sequences%20Interview%20Questions) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./49_Amortization.md) | [Next](./51_Anagram-Check-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/51_Anagram-Check-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/51_Anagram-Check-Interview-Problem.md new file mode 100644 index 0000000..5b5b01f --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/51_Anagram-Check-Interview-Problem.md @@ -0,0 +1,61 @@ +# 51. Anagram Check - Interview Problem + +
+

Interview Problems:

+ +## Anagram Check + +### Problem + +Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + +For example: + + "public relations" is an anagram of "crap built on lies." + + "clint eastwood" is an anagram of "old west action" + +**Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** + +## Solution + +Fill out your solution below: + +```python +def anagram(s1,s2): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class AnagramTest(object): + + def test(self,sol): + assert_equal(sol('go go go','gggooo'),True) + assert_equal(sol('abc','cba'),True) + assert_equal(sol('hi man','hi man'),True) + assert_equal(sol('aabbcc','aabbc'),False) + assert_equal(sol('123','1 2'),False) + print("ALL TEST CASES PASSED") + +# Run Tests +t = AnagramTest() +t.test(anagram) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./50_Interview-Problems-Arrays.md) | [Next](./52_Anagram-Check-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/52_Anagram-Check-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/52_Anagram-Check-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..a63e016 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/52_Anagram-Check-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 52. Anagram Check - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [01-anagram-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-assert.py) +- [01-anagram-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-doctest.py) +- [01-anagram-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./51_Anagram-Check-Interview-Problem.md) | [Next](./53_Array-Pair-Sum-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/53_Array-Pair-Sum-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/53_Array-Pair-Sum-Interview-Problem.md new file mode 100644 index 0000000..bf88275 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/53_Array-Pair-Sum-Interview-Problem.md @@ -0,0 +1,63 @@ +# 53. Array Pair Sum - Interview Problem + +
+

Interview Problems:

+ +## Array Pair Sum + +### Problem + +Given an integer array, output all the ***unique*** pairs that sum up to a specific value **k**. + +So the input: + + pair_sum([1,3,2,2],4) + +would return **2** pairs: + + (1,3) + (2,2) + +**NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS** + +## Solution + +Fill out your solution below: + +```python +def pair_sum(arr,k): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class TestPair(object): + + def test(self,sol): + assert_equal(sol([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + assert_equal(sol([1,2,3,1],3),1) + assert_equal(sol([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +#Run tests +t = TestPair() +t.test(pair_sum) +print("All tests passed!") +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./52_Anagram-Check-Interview-Problem-SOLUTION.md) | [Next](./54_Array-Pair-Sum-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/54_Array-Pair-Sum-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/54_Array-Pair-Sum-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..b940ae8 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/54_Array-Pair-Sum-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 54. Array Pair Sum - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [02-array-pair-sum-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-assert.py) +- [02-array-pair-sum-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-doctest.py) +- [02-array-pair-sum-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./53_Array-Pair-Sum-Interview-Problem.md) | [Next](./55_Find-the-Missing-Element-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/55_Find-the-Missing-Element-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/55_Find-the-Missing-Element-Interview-Problem.md new file mode 100644 index 0000000..7abd921 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/55_Find-the-Missing-Element-Interview-Problem.md @@ -0,0 +1,61 @@ +# 55. Find the Missing Element - Interview Problem + +
+

Interview Problems:

+ +## Find the Missing Element + +### Problem + +Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. + +Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array. + +Input: + + finder([1,2,3,4,5,6,7],[3,7,2,1,4,6]) + +Output: + + 5 is the missing number + +## Solution + +Fill out your solution below: + +```python +ddef finder(arr1,arr2): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class TestFinder(object): + + def test(self,sol): + assert_equal(sol([5,5,7,7],[5,7,7]),5) + assert_equal(sol([1,2,3,4,5,6,7],[3,7,2,1,4,6]),5) + assert_equal(sol([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]),6) + print('ALL TEST CASES PASSED') + +# Run test +t = TestFinder() +t.test(finder) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./54_Array-Pair-Sum-Interview-Problem-SOLUTION.md) | [Next](./56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..1618f04 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 56. Find the Missing Element - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [03-find-the-missing-element-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-assert.py) +- [03-find-the-missing-element-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-doctest.py) +- [03-find-the-missing-element-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./55_Find-the-Missing-Element-Interview-Problem.md) | [Next](./57_Largest-Continuous-Sum-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/57_Largest-Continuous-Sum-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/57_Largest-Continuous-Sum-Interview-Problem.md new file mode 100644 index 0000000..4782247 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/57_Largest-Continuous-Sum-Interview-Problem.md @@ -0,0 +1,49 @@ +# 57. Largest Continuous Sum - Interview Problem + +
+

Interview Problems:

+ +## Largest Continuous Sum + +### Problem +Given an array of integers (positive and negative) find the largest continuous sum. + +## Solution + +Fill out your solution below: + +```python +def large_cont_sum(arr): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class LargeContTest(object): + def test(self,sol): + assert_equal(sol([1,2,-1,3,4,-1]),9) + assert_equal(sol([1,2,-1,3,4,10,10,-10,-1]),29) + assert_equal(sol([-1,1]),1) + print('ALL TEST CASES PASSED') + +#Run Test +t = LargeContTest() +t.test(large_cont_sum) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md) | [Next](./58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..5c45ccc --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 58. Largest Continuous Sum - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [04-largest-continuous-sum-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-assert.py) +- [04-largest-continuous-sum-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-doctest.py) +- [04-largest-continuous-sum-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./57_Largest-Continuous-Sum-Interview-Problem.md) | [Next](./59_Sentence-Reversal-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/59_Sentence-Reversal-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/59_Sentence-Reversal-Interview-Problem.md new file mode 100644 index 0000000..f82d43b --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/59_Sentence-Reversal-Interview-Problem.md @@ -0,0 +1,68 @@ +# 59. Sentence Reversal - Interview Problem + +
+

Interview Problems:

+ +## Sentence Reversal + +### Problem + +Given a string of words, reverse all the words. For example: + +Given: + + 'This is the best' + +Return: + + 'best the is This' + +As part of this exercise you should remove all leading and trailing whitespace. So that inputs such as: + + ' space here' and 'space here ' + +both become: + + 'here space' + +## Solution + +Fill out your solution below: + +```python +def rev_word(s): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class ReversalTest(object): + + def test(self,sol): + assert_equal(sol(' space before'),'before space') + assert_equal(sol('space after '),'after space') + assert_equal(sol(' Hello John how are you '),'you are how John Hello') + assert_equal(sol('1'),'1') + print("ALL TEST CASES PASSED") + +# Run and test +t = ReversalTest() +t.test(rev_word) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md) | [Next](./60_Sentence-Reversal-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/60_Sentence-Reversal-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/60_Sentence-Reversal-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..31db4ca --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/60_Sentence-Reversal-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 60. Sentence Reversal - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [05-sentence-reversal-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-assert.py) +- [05-sentence-reversal-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-doctest.py) +- [05-sentence-reversal-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./59_Sentence-Reversal-Interview-Problem.md) | [Next](./61_String-Compression-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/61_String-Compression-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/61_String-Compression-Interview-Problem.md new file mode 100644 index 0000000..c4a4dba --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/61_String-Compression-Interview-Problem.md @@ -0,0 +1,53 @@ +# 61. String Compression - Interview Problem + +
+

Interview Problems:

+ +## String Compression + +### Problem + +Given a string in the form 'AAAABBBBCCCCCDDEEEE' compress it to become 'A4B4C5D2E4'. For this problem, you can falsely "compress" strings of single or double letters. For instance, it is okay for 'AAB' to return 'A2B1' even though this technically takes more space. + +The function should also be case sensitive, so that a string 'AAAaaa' returns 'A3a3'. + +## Solution + +Fill out your solution below: + +```python +def compress(s): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class TestCompress(object): + + def test(self, sol): + assert_equal(sol(''), '') + assert_equal(sol('AABBCC'), 'A2B2C2') + assert_equal(sol('AAABCCDDDDD'), 'A3B1C2D5') + print('ALL TEST CASES PASSED') + +# Run Tests +t = TestCompress() +t.test(compress) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./60_Sentence-Reversal-Interview-Problem-SOLUTION.md) | [Next](./62_String-Compression-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/62_String-Compression-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/62_String-Compression-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..38859b4 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/62_String-Compression-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 62. String Compression - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [06-string-compression-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-assert.py) +- [06-string-compression-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-doctest.py) +- [06-string-compression-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./61_String-Compression-Interview-Problem.md) | [Next](./63_Unique-Characters-in-a-String-Interview-Problem.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/63_Unique-Characters-in-a-String-Interview-Problem.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/63_Unique-Characters-in-a-String-Interview-Problem.md new file mode 100644 index 0000000..8cbb444 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/63_Unique-Characters-in-a-String-Interview-Problem.md @@ -0,0 +1,50 @@ +# 63. Unique Characters in a String - Interview Problem + +
+

Interview Problems:

+ +## Unique Characters in String + +### Problem +Given a string,determine if it is compreised of all unique characters. For example, the string 'abcde' has all unique characters and should return True. The string 'aabcde' contains duplicate characters and should return false. + +## Solution + +Fill out your solution below: + +```python +def uni_char(s): + pass +``` + +## Test Your Solution + +Run the cell below to test your solution + +```python +from nose.tools import assert_equal + +class TestUnique(object): + + def test(self, sol): + assert_equal(sol(''), True) + assert_equal(sol('goo'), False) + assert_equal(sol('abcdefg'), True) + print('ALL TEST CASES PASSED') + +# Run Tests +t = TestUnique() +t.test(uni_char) +``` + +
+ + + +## Resources for this lecture + + + +--- + +[Previous](./62_String-Compression-Interview-Problem-SOLUTION.md) | [Next](./64_Unique-Characters-in-a-String-Interview-Problem-SOLUTION.md) \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/64_Unique-Characters-in-String-Interview-Problem-SOLUTION.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/64_Unique-Characters-in-String-Interview-Problem-SOLUTION.md new file mode 100644 index 0000000..3989837 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/64_Unique-Characters-in-String-Interview-Problem-SOLUTION.md @@ -0,0 +1,18 @@ +# 64. Unique Characters in String - Interview Problem - SOLUTION + +
+

CodeBase:

+ +- [07-unique-characters-in-string-assert.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-assert.py) +- [07-unique-characters-in-string-doctest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-doctest.py) +- [07-unique-characters-in-string-unittest.py](../../codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-unittest.py) + +
+ +## Resources for this lecture + + + +--- + +[Previous](./63) | [Next]() \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/Readme.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/Readme.md index e69de29..bc114b3 100644 --- a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/Readme.md +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/Readme.md @@ -0,0 +1,407 @@ +# Python for Data Structures, Algorithms, and Interviews! + +- [Python for Data Structures, Algorithms, and Interviews!](https://www.udemy.com/course/python-for-data-structures-algorithms-and-interviews) + +- [https://github.com/BloomTech-DS/Python-for-Algorithms--Data-Structures--and-Interviews](https://github.com/BloomTech-DS/Python-for-Algorithms--Data-Structures--and-Interviews) + +Get a kick start on your career and ace your coding interviews! + +## What you'll learn +- Create a great resume +- Have a LinkedIn and Github profile for recruiters +- Understand all major Data Structures and Algorithms +- Ace coding interviews after preparing with the course's mock interviews + +## Course content + +25 sections • 228 lectures • 17h 10m total length + +
+ Section 1: Course Setup + + - [1. Course Introduction](1_Course-Introduction.md) + - [2. Full Course Curriculum Overview](2_Full-Course-Curriculum-Overview.md) + - [3. How to get help for the Course!](3_How-to-get-help-for-the-Course.md) + - [4. Course FAQ](4_Course-FAQ.md) +
+ +
+ Section 2: Company and Job Types + + - [5. ]() + - [6. ]() +
+ +
+ Section 3: Resume Preparation + + - [7. ]() + - [8. ]() + - [9. ]() + - [10. ]() +
+ +
+ Section 4: Online Presence + + - [11. ]() + - [12. ]() + - [13. ]() +
+ +
+ Section 5: Networking + + - [14. ]() + - [15. ]() +
+ +
+ Section 6: Job Searching + + - [16. ]() + - [17. ]() + - [18. ]() + - [19. ]() + - [20. ]() +
+ +
+ Section 7: During the Interview (Non-Technical) + + - [21. ]() + - [22. ]() + - [23. ]() + - [24. ]() + - [25. ]() +
+ +
+ Section 8: Post Interview + + - [26. ]() + - [27. ]() + - [28. ]() +
+ +
+ Section 9: Technical Break Section + + - [29. ]() + - [30. ]() + - [31. ]() +
+ +
+ Section 10: Introduction to Jupyter Notebooks + + - [32. ]() + - [33. ]() + - [34. ]() + - [35. ]() + - [36. ]() + - [37. ]() +
+ +
+ Section 11: Algorithm Analysis and Big O + + - [38. Algorithm Analysis and Big O Section Overview](38_Algorithm-Analysis-and-Big-O-Section-Overview.md) + - [39. Introduction to Algorithm Analysis and Big O](39_Introduction-to-Algorithm-Analysis-and-Big-O.md) + - [40. Big O Notation](40_Big-O-Notation.md) + - [41. Big O Examples](41_Big-O-Examples.md) + - [42. Homework Reading Asssignment](42_Homework-Reading-Asssignment.md) + - [43. Big O for Python Data Structures](43_Big-O-for-Python-Data-Structures.md) + - [44. Big-O Reference Cheat Sheet](44-Big-O-Reference-Cheat-Sheet.md) +
+ +
+ Section 12: Array Sequences + + - [45. Introduction to Array Based Sequences](45_Introduction-to-Array-Based-Sequences.md) + - [46. Low Level Arrays](46_Low-Level-Arrays.md) + - [47. Dynamic Array](47_Dynamic-Array.md) + - [48. Dynamic Array Excercise](48_Dynamic-Array-Excercise.md) + - [49. Amortizatio](49_Amortization.md) + - [50. Interview Problems - Arrays](50_Interview-Problems-Arrays.md) + - [51. Anagram Check - Interview Problem](51_Anagram-Check-Interview-Problem.md) + - [52. Anagram Check - Interview Problem - SOLUTION](52_Anagram-Check-Interview-Problem-SOLUTION.md) + - [53. Array Pair Sum - Interview Problem](53_Array-Pair-Sum-Interview-Problem.md) + - [54. Array Pair Sum - Interview Problem - SOLUTION](54_Array-Pair-Sum-Interview-Problem-SOLUTION.md) + - [55. Find the Missing Element - Interview Problem](55_Find-the-Missing-Element-Interview-Problem.md) + - [56. Find the Missing Element - Interview Problem - SOLUTION](56_Find-the-Missing-Element-Interview-Problem-SOLUTION.md) + - [57. Largest Continuous Sum - Interview Problem](57_Largest-Continuous-Sum-Interview-Problem.md) + - [58. Largest Continuous Sum - Interview Problem - SOLUTION](58_Largest-Continuous-Sum-Interview-Problem-SOLUTION.md) + - [59. Sentence Reversal - Interview Problem](59_Sentence-Reversal-Interview-Problem.md) + - [60. Sentence Reversal - Interview Problem - SOLUTION](60_Sentence-Reversal-Interview-Problem-SOLUTION.md) + - [61. String Compression - Interview Problem](61_String-Compression-Interview-Problem.md) + - [62. String Compression - Interview Problem - SOLUTION](62_String-Compression-Interview-Problem-SOLUTION.md) + - [63. Unique Characters in a String - Interview Problem](63_Unique-Characters-in-a-String-Interview-Problem.md) + - [64. Unique Characters in String - Interview Problem - SOLUTION](64_Unique-Characters-in-String-Interview-Problem-SOLUTION.md) +
+ +
+ Section 13: Stacks Queues and Deques + + - [65. ]() + - [66. ]() + - [67. ]() + - [68. ]() + - [69. ]() + - [70. ]() + - [71. ]() + - [72. ]() + - [73. ]() + - [74. ]() + - [75. ]() + - [76. ]() + - [77. ]() + - [78. ]() + - [79. ]() +
+ +
+ Section 14: Linked List + + - [80. ]() + - [81. ]() + - [82. ]() + - [83. ]() + - [84. ]() + - [85. ]() + - [86. ]() + - [87. ]() + - [88. ]() + - [89. ]() + - [90. ]() + - [91. ]() + - [92. ]() +
+ +
+ Section 15: Recursion + + - [93. ]() + - [94. ]() + - [95. ]() + - [96. ]() + - [97. ]() + - [98. ]() + - [99. ]() + - [100. ]() + - [101. ]() + - [102. ]() + - [103. ]() + - [104. ]() + - [105. ]() +
+ +
+ Section 16: Trees + + - [106. ]() + - [107. ]() + - [108. ]() + - [109. ]() + - [110. ]() + - [111. ]() + - [112. ]() + - [113. ]() + - [114. ]() + - [115. ]() + - [116. ]() + - [117. ]() + - [118. ]() + - [119. ]() + - [120. ]() + - [121. ]() +
+ +
+ Section 17: Searching and Sorting + + - [122. ]() + - [123. ]() + - [124. ]() + - [125. ]() + - [126. ]() + - [127. ]() + - [128. ]() + - [129. ]() + - [130. ]() + - [131. ]() + - [132. ]() + - [133. ]() + - [134. ]() + - [135. ]() + - [136. ]() + - [137. ]() + - [138. ]() + - [139. ]() + - [140. ]() + - [141. ]() + - [142. ]() + - [143. ]() + - [144. ]() + - [145. ]() + - [146. ]() + - [147. ]() + - [148. ]() + - [149. ]() + - [150. ]() + - [151. ]() +
+ +
+ Section 18: Graph Algorithms + + - [152. ]() + - [153. ]() + - [154. ]() + - [155. ]() + - [156. ]() + - [157. ]() + - [158. ]() + - [159. ]() + - [160. ]() + - [161. ]() + - [162. ]() + - [163. ]() + - [164. ]() + - [165. ]() +
+ +
+ Section 19: Riddles + + - [166. ]() + - [167. ]() + - [168. ]() + - [169. ]() + - [170. ]() + - [171. ]() + - [172. ]() + - [173. ]() + - [174. ]() + - [175. ]() + - [176. ]() + - [177. ]() + - [178. ]() + - [179. ]() + - [180. ]() +
+ +
+ Section 20: Introduction to Mock Interview Section + + - [181. ]() + - [182. ]() + - [183. ]() + - [184. ]() + - [185. ]() +
+ +
+ Section 21: Mock Interview 1 - E-Commerce Company + + - [186. ]() + - [187. ]() + - [188. ]() + - [189. ]() + - [190. ]() + - [191. ]() + - [192. ]() + - [193. ]() + - [194. ]() + - [195. ]() +
+ +
+ Section 22: Mock Interview 2 - Large Search Engine Company + + - [196. ]() + - [197. ]() + - [198. ]() + - [199. ]() + - [200. ]() + - [201. ]() + - [202. ]() + - [203. ]() + - [204. ]() + - [205. ]() + - [206. ]() + - [207. ]() +
+ +
+ Section 23: Mock Interview 3 - Ride Share Start-Up Company + + - [208. ]() + - [209. ]() + - [210. ]() + - [211. ]() + - [212. ]() + - [213. ]() + - [214. ]() + - [215. ]() + - [216. ]() + - [217. ]() +
+ +
+ Section 24: Mock Interview 4 - Social Network Company + + - [218. ]() + - [219. ]() + - [220. ]() + - [221. ]() + - [222. ]() + - [223. ]() + - [224. ]() + - [225. ]() + - [226. ]() + - [227. ]() +
+ +
+ Section 25: BONUS SECTION: THANK YOU! + + - [228. ]() +
+ +## Requirements + +Basic to Intermediate Python skills. + +## Description + +PLEASE NOTE: IF YOU ARE A COMPLETE BEGINNER TO PYTHON, CHECK OUT MY OTHER COURSE: **COMPLETE PYTHON BOOTCAMP** TO LEARN PYTHON! + +**Welcome to Python for Data Structures, Algorithms and Interviews!** + +This is the most comprehensive course online to help you ace your coding interviews and learn about Data Structures and Algorithms! This course takes advantage of the easy to read Python programming language to efficiently teach you what you need to know to land the tech job of your dreams! + +This course will teach you everything you need to know to get a great job in the software technology field, including: + +- Creating a great resume +- Creating LinkedIn and GitHub profiles for recruiters to find +- Building and leveraging a network for job opportunities +- The latest job searching tools available online +- Non-Technical Interview Questions and Answers +- Post-Interview topics (Salary Negotiation and References Preparation) +- Jupyter Notebooks Overview +- Algorithm Analysis and Big-O Notation +- Array Sequences +- Stacks Queues and Deques +- Linked Lists +- Recursion +- Trees +- Searching and Sorting Algorithms +- Graph Algorithms +- Riddles and Brainteasers +- 4 Mock Interviews! + +**Achieve your career goals and get a fantastic job in technology by enrolling in this course!** + +## Who this course is for: +- Students familiar with Python programming looking to start a career in tech! \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.1_How_to_use_ctypes_in_python.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.1_How_to_use_ctypes_in_python.md new file mode 100644 index 0000000..79cdcdc --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.1_How_to_use_ctypes_in_python.md @@ -0,0 +1,69 @@ +# 48.1 How to us `ctypes` in Python? + +`ctypes` is a Python module that allows you to call functions and work with dynamic libraries written in C or C++ directly from Python. It provides a way to interact with low-level memory and data types in a C-compatible way. + +Here's a brief overview of how to use `ctypes` in Python: + +1. Import the `ctypes` module: + +```python +import ctypes +``` + +2. Define C data types and structures: + +Before using `ctypes`, you need to define C data types and structures that will be used to interact with C functions or libraries. You can use `ctypes` to represent basic C data types like int, float, double, etc., and define complex C data structures using `ctypes` classes like `Structure` and `Union`. + +3. Load the shared library: + +To use C functions from a shared library (dynamic library) in Python, you need to load the library using `ctypes.CDLL` or `ctypes.CWindll` (for Windows DLLs). + +4. Access C functions from the loaded library: + +Once the library is loaded, you can access C functions from it and call them as if they were Python functions. You need to specify the function's return type and argument types using `ctypes` data types. + +5. Handle c-compound data types: + +When calling C functions, you may need to pass C-compatible data to and from these functions. `ctypes` provides functions to create C-compatible arrays, pointers, and strings. + +**Here's a simple example to illustrate how to use ctypes:** + +Suppose you have a simple C library named "my_library" with the following functions: + +```c +// my_library.h +int add(int a, int b); +double multiply(double x, double y); +``` + +1. Create a shared library from the C code: + +```bash +gcc -shared -o my_library.so -fPIC my_library.c +``` + +2. In Python, you can use `ctypes` to call these functions: + +```python +import ctypes + +# Load the shared library +my_library = ctypes.CDLL('./my_library.so') + +# Specify function return types and argument types +my_library.add.restype = ctypes.c_int +my_library.add.argtypes = [ctypes.c_int, ctypes.c_int] + +my_library.multiply.restype = ctypes.c_double +my_library.multiply.argtypes = [ctypes.c_double, ctypes.c_double] + +# Call the C functions from Python +result_add = my_library.add(10, 5) +result_multiply = my_library.multiply(3.14, 2.0) + +print("Result of add:", result_add) # Output: Result of add: 15 +print("Result of multiply:", result_multiply) # Output: Result of multiply: 6.28 + +``` + +This example demonstrates how to use `ctypes` to call C functions from a shared library in Python. You can extend this approach to work with more complex C libraries and data structures. However, keep in mind that working with `ctypes` requires some knowledge of C and low-level memory management, so use it with caution. \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.2_How-to-use-make_array.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.2_How-to-use-make_array.md new file mode 100644 index 0000000..cb0c348 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.2_How-to-use-make_array.md @@ -0,0 +1,42 @@ +# 48.2 how to use `make_array`? + +To use the `make_array` method, you need to have an instance of the `DynamicArray` class (as defined in the initial code) since the method is part of that class. Once you have an instance, you can call the `make_array` method to create a new dynamic array (C-style array) with a specified capacity. Here's how you can use it: + +```python +import ctypes + +class DynamicArray(object): + """ + DYNAMIC ARRAY CLASS (Similar to Python List) + """ + + # ... (Other methods and constructor as defined in the initial code) ... + + def make_array(self, new_cap): + return (new_cap * ctypes.py_object)() + +# Creating an instance of DynamicArray +dynamic_array = DynamicArray() + +# Using make_array to create a new array +new_capacity = 10 +new_array = dynamic_array.make_array(new_capacity) + +# The new_array is a dynamic array with a capacity of 10. +# It can store Python objects, similar to a Python list. +# However, it's not directly accessible as a Python list, and you need to work with it using ctypes or other low-level approaches. + +# For example, you can store values in the new array using ctypes: +for i in range(new_capacity): + new_array[i] = i * 2 + +# Accessing elements in the new array: +for i in range(new_capacity): + print(new_array[i]) + +# Note: This new_array is a C-style array and not directly usable as a Python list. +# If you want a dynamic array similar to Python's list, you should use the DynamicArray class and its append method as described in the initial code. + +``` + +It's essential to understand that the `make_array` method creates a low-level dynamic array using C-style array concepts from the `ctypes` module. While it can store Python objects like a list, it is not directly accessible using standard Python list methods. If you want a dynamic array with list-like behavior, you should use the `DynamicArray` class with its `append` method, as shown in the initial code. The `DynamicArray` class handles the low-level memory management and provides a more user-friendly interface for working with dynamic arrays in Python. \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.3_Why_double_size_in_append_method.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.3_Why_double_size_in_append_method.md new file mode 100644 index 0000000..a34b8e6 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.3_Why_double_size_in_append_method.md @@ -0,0 +1,7 @@ +# 48.3 Why double size in `append(self, ele)`? + +In the original code, the line `self._resize(2 * self.capacity)` is used to double the capacity of the dynamic array whenever it becomes full. Doubling the capacity helps reduce the number of resizing operations and provides an amortized constant-time complexity for most `append` operations, which is a common resizing strategy for dynamic arrays. + +However, this strategy may not be the most efficient in all scenarios. Sometimes, you may have a use case where you expect the dynamic array to grow slowly, and doubling the capacity could result in a significant waste of memory. + +Keep in mind that the choice of resizing strategy depends on the specific use case and the expected pattern of element additions. If you expect frequent and large batches of elements to be appended, the doubling strategy might be more appropriate. On the other hand, if you expect a gradual growth or occasional additions, the incremental strategy can be more memory-friendly. \ No newline at end of file diff --git a/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.4_use-sys.getsizeof()-to-estimate-the-memory-usage-by-DynamicArray.md b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.4_use-sys.getsizeof()-to-estimate-the-memory-usage-by-DynamicArray.md new file mode 100644 index 0000000..2013447 --- /dev/null +++ b/Curricula/Python-for-Data-Structures-Algorithms-and-Interviews/notes/48.4_use-sys.getsizeof()-to-estimate-the-memory-usage-by-DynamicArray.md @@ -0,0 +1,50 @@ +# How to use `sys.getsizeof()` or `tracemalloc` to get an estimate of the memory usage of the `DynamicArray`? + +you can use `sys.getsizeof()` to get an estimate of the memory usage of the `DynamicArray` and its underlying array. However, keep in mind that the value returned by `sys.getsizeof()` might not provide an accurate representation of the actual memory usage. + +`sys.getsizeof()` returns the size of the object in bytes, but it doesn't take into account the memory overhead of the Python interpreter or other optimizations that Python might apply. Additionally, `sys.getsizeof()` only provides the size of the Python object and not the memory used by the elements stored in the array. + +Here's an example of how you can use `sys.getsizeof()` to get the size of the `DynamicArray` object: + +```python +import sys + +# Assuming the DynamicArray class is defined as before +dynamic_array = DynamicArray() + +# Append some elements to the array +for i in range(100): + dynamic_array.append(i) + +# Get the size of the DynamicArray object in bytes +size_of_dynamic_array = sys.getsizeof(dynamic_array) +print("Size of DynamicArray:", size_of_dynamic_array, "bytes") +``` + +However, to get a more accurate memory usage estimate, you could use the `tracemalloc` module, which provides more detailed memory tracing capabilities. Using `tracemalloc`, you can measure memory usage before and after specific operations, allowing you to see how much memory your data structures consume in total. Here's an example of how you can use `tracemalloc`: + +```python +import tracemalloc + +# Assuming the DynamicArray class is defined as before +dynamic_array = DynamicArray() + +# Enable tracing +tracemalloc.start() + +# Append some elements to the array +for i in range(100): + dynamic_array.append(i) + +# Measure memory usage after appending elements +snapshot = tracemalloc.take_snapshot() +top_stats = snapshot.statistics("lineno") + +for stat in top_stats[:10]: + print(stat) + +# Disable tracing +tracemalloc.stop() +``` + +Keep in mind that memory usage can be affected by many factors, and accurately measuring memory consumption in Python can be challenging. It's essential to understand the limitations of each method and use them accordingly based on your specific use case. \ No newline at end of file diff --git a/Curricula/edabit-py/Readme.md b/Curricula/edabit-py/Readme.md new file mode 100644 index 0000000..2c8a410 --- /dev/null +++ b/Curricula/edabit-py/Readme.md @@ -0,0 +1,14 @@ +# edabit + +- [edabit](https://edabit.com/) + +## Content + +
+ RegEx + +- [RegEx X-A: Word Character Class](./RegEx/RegEx_X-A_Word-Character-Class.md) + +- [RegEx XV: Alternation]() + +
\ No newline at end of file diff --git a/Curricula/edabit-py/RegEx/RegEx-XV_Alternation.md b/Curricula/edabit-py/RegEx/RegEx-XV_Alternation.md new file mode 100644 index 0000000..bfbf6e1 --- /dev/null +++ b/Curricula/edabit-py/RegEx/RegEx-XV_Alternation.md @@ -0,0 +1,43 @@ +# RegEx XV: Alternation + +- [RegEx XV: Alternation](https://edabit.com/challenge/9ZAHTYWTP5c7FW4RY) + +**The vertical bar** `|` is the equivalent to "or" in RegEx. The regular expression `x|y` matches either "x" or "y". Write the **regular expression** that will match all `red flag` and `blue flag` in a string. You must use `|` in your expression. Flags can come in any order. + +**Examples** + +``` +txt1 = "red flag blue flag" +txt2 = "yellow flag red flag blue flag green flag" +txt3 = "pink flag red flag black flag blue flag green flag red flag" +pattern = "yourregularexpressionhere" + +re.findall(pattern, txt1) ➞ ["red flag", "blue flag"] +re.findall(pattern, txt2) ➞ ["red flag", "blue flag"] +re.findall(pattern, txt3) ➞ ["red flag", "blue flag", "red flag"] +``` + +**Notes** + +You **don't** need to write a function, just the pattern. +Do **not** remove `import re` from the code. +Find more info on RegEx and alternation in the Resources tab. +You can find all the challenges of this series in my [Basic RegEx](https://edabit.com/collection/8PEq2azWDtAZWPFe2) collection. + +**Solution** + +``` +import re + +pattern = "red flag|blue flag" +``` + +**Solution 2** + +- [cvf](https://edabit.com/user/yjtdwc2AC4jA2RWtn) + +``` +import re + +pattern = "(?:red|blue) flag" +``` \ No newline at end of file diff --git a/Curricula/edabit-py/RegEx/RegEx_X-A_Word-Character-Class.md b/Curricula/edabit-py/RegEx/RegEx_X-A_Word-Character-Class.md new file mode 100644 index 0000000..2cc9ad9 --- /dev/null +++ b/Curricula/edabit-py/RegEx/RegEx_X-A_Word-Character-Class.md @@ -0,0 +1,30 @@ +# RegEx X-A: Word Character Class + +[RegEx X-A: Word Character Class](https://edabit.com/challenge/mtfCmMo9fL5yqB3Sy) + +Write the regular expression that matches all alphabetic characters in a string. Use the character class \w in your expression. + +**Example** + +```python + txt = "**^&$Regular#$%Expressions$%$$%^**" + pattern = "yourregularexpressionhere" + + " ".join(re.findall(pattern, txt)) ➞ "Regular Expressions" +``` + +**Notes** + +You **don't** need to write a function, just the pattern. +Do **not** remove `import re` from the code. +Find more info on RegEx and alternation in the Resources tab. +You can find all the challenges of this series in my [Basic RegEx](https://edabit.com/collection/8PEq2azWDtAZWPFe2) collection. + +**Solution** + +``` +import re + +pattern = '\w+' +``` + diff --git a/codebase/.DS_Store b/codebase/.DS_Store index 9d10ed7..664820c 100644 Binary files a/codebase/.DS_Store and b/codebase/.DS_Store differ diff --git a/codebase/python-ds-interview/.DS_Store b/codebase/python-ds-interview/.DS_Store new file mode 100644 index 0000000..dba0c0b Binary files /dev/null and b/codebase/python-ds-interview/.DS_Store differ diff --git a/codebase/python-ds-interview/01-intro-big-o/01-intro-analysis-big-o.py b/codebase/python-ds-interview/01-intro-big-o/01-intro-analysis-big-o.py new file mode 100644 index 0000000..daf9c7a --- /dev/null +++ b/codebase/python-ds-interview/01-intro-big-o/01-intro-analysis-big-o.py @@ -0,0 +1,34 @@ +import timeit + +# First function (Note the use of range since this is in Python 3) +def sum1(n): + ''' + Take an input of n and return the sum of the numbers from 0 to n + ''' + final_sum = 0 + for x in range(n+1): + final_sum += x + + return final_sum + +print(sum1(10)) + +timer1 = timeit.Timer('sum1(10)', globals=globals()) + +time_taken1 = timer1.timeit(number=1000) + +print(f"Time taken by sum1: {time_taken1:.6f} seconds") + +def sum2(n): + """ + Take an input of n and return the sum of the numbers from 0 to n + """ + return (n*(n+1))/2 + +print(sum2(10)) + +timer2 = timeit.Timer('sum2(10)', globals=globals()) + +time_taken2 = timer2.timeit(number=1000) + +print(f"Time taken by sum2: {time_taken2:.6f} seconds") diff --git a/codebase/python-ds-interview/01-intro-big-o/02-big-o-notion.py b/codebase/python-ds-interview/01-intro-big-o/02-big-o-notion.py new file mode 100644 index 0000000..2c0ac89 --- /dev/null +++ b/codebase/python-ds-interview/01-intro-big-o/02-big-o-notion.py @@ -0,0 +1,30 @@ +import numpy as np +import matplotlib.pyplot as plt + +# Import math module specifically for the log function +from math import log + +# Set up runtime comparisons +n = np.linspace(1, 10, 1000) +labels = ['Constant', 'Logarithmic', 'Linear', 'Log Linear', 'Quadratic', 'Cubic', 'Exponential'] +big_o = [np.ones(n.shape), np.log(n), n, n*np.log(n), n**2, n**3, 2**n] + +# Plot setup +plt.figure(figsize=(12, 10)) +plt.ylim(0, 50) + +for i in range(len(big_o)): + plt.plot(n, big_o[i], label=labels[i]) + +plt.legend(loc=0) +plt.ylabel('Relative Runtime') +plt.xlabel('n') + +fig = plt.gcf() +fig.set_size_inches(12, 4) +fig.savefig('../../../imgs/py-ds/02-big-o-notion.png', dpi=300) + + + +# Display the plot +plt.show() \ No newline at end of file diff --git a/codebase/python-ds-interview/01-intro-big-o/03-big-o-examples.py b/codebase/python-ds-interview/01-intro-big-o/03-big-o-examples.py new file mode 100644 index 0000000..2c02f00 --- /dev/null +++ b/codebase/python-ds-interview/01-intro-big-o/03-big-o-examples.py @@ -0,0 +1,116 @@ +# O(1) Constant example + +def func_constant(values): + ''' + Prints first item in a list of values. + ''' + print(values[0]) + +func_constant([1,2,3]) + +# O(n) Linear example + +def func_lin(lst): + ''' + Takes in list and prints out all values + ''' + for val in lst: + print(val) + +func_lin([1,2,3]) + +# O(n^2) Quadratic example + +def func_quad(lst): + ''' + Prints pairs for every item in list. + ''' + for item_1 in lst: + for item_2 in lst: + print(item_1,item_2) + +func_quad([1,2,3]) + +# Calculating Scale of Big-O + +def print_once(lst): # O(n) + ''' + Prints all items once + ''' + for val in lst: + print(val) + +print_once([1,2,3]) + +def print_3(lst): # O(3n) --> O(n) + ''' + Prints all items three times + ''' + for val in lst: + print(val) + + for val in lst: + print(val) + + for val in lst: + print(val) + +print_3([1,2,3]) + +def comp(lst): # O(1 + 1/2n + 10) --> O(n) + ''' + This function prints the first item O(1) + Then is prints the first 1/2 of the list O(n/2) + Then prints a string 10 times O(10) + ''' + print(lst[0]) + + midpoint = len(lst)//2 + + for val in lst[:midpoint]: + print(val) + + for x in range(10): + print('number') + +print(comp([1,2,3,4,5,6,7,8,9,10])) + + # Worst Case vs Best Case + +def matcher(lst,match): # O(n) + ''' + Given a list lst, return a boolean indicating if match item is in the list + ''' + for item in lst: + if item == match: + return True + return False + +# Best case: O(1) --> item is first item in list +# Worst case: O(n) --> item is not in list or is last item in list + +print(matcher([1,2,3,4,5],1)) + +# Space Complexity + +def printer(n=10): # O(1) + ''' + Prints "hello world!" n times + ''' + for x in range(n): + print('Hello World!') + +printer() + +def create_list(n): # O(n) + ''' + Creates a list containing 1 to n + ''' + new_list = [] + + for num in range(n): + new_list.append('new') + + return new_list + +print(create_list(5)) \ No newline at end of file diff --git a/codebase/python-ds-interview/01-intro-big-o/04-big-o-for-python-data-structures.py b/codebase/python-ds-interview/01-intro-big-o/04-big-o-for-python-data-structures.py new file mode 100644 index 0000000..e69de29 diff --git a/codebase/python-ds-interview/02-array-sequences/.DS_Store b/codebase/python-ds-interview/02-array-sequences/.DS_Store new file mode 100644 index 0000000..1dea0d1 Binary files /dev/null and b/codebase/python-ds-interview/02-array-sequences/.DS_Store differ diff --git a/codebase/python-ds-interview/02-array-sequences/03_dynamic_array.py b/codebase/python-ds-interview/02-array-sequences/03_dynamic_array.py new file mode 100644 index 0000000..ac1c303 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/03_dynamic_array.py @@ -0,0 +1,22 @@ +import sys + +# Set n +n = 10 + +data = [] + +for i in range(n): + + # Number of elements + a = len(data) + + # Actual size in bytes + b = sys.getsizeof(data) + + print('Length: {0:3d}; Size in bytes: {1:4d}'.format(a, b)) + + # increase length by one + data.append(n) + + + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/04_dynamic_array_exercise.py b/codebase/python-ds-interview/02-array-sequences/04_dynamic_array_exercise.py new file mode 100644 index 0000000..6fc40a6 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/04_dynamic_array_exercise.py @@ -0,0 +1,121 @@ +class M(object): + + def public(self): + print('Use Tab to see me!') + + def _private(self): + print("You won't be able to Tab to see me!") + +m = M() + +m.public() + +m._private() + +import ctypes + +class DynamicArray(object): + """ + DYNAMIC ARRAY CLASS (Similar to Python List) + """ + + def __init__(self): + self.n = 0 + self.capacity = 1 + self.A = self.make_array(self.capacity) + + def __len__(self): + return self.n + + def __getitem__(self, k): + + if not 0 <= k < self.n: + return IndexError('k is out of bounds!') + + return self.A[k] + + def append(self, ele): + + if self.n == self.capacity: + self._resize(2*self.capacity +1) # Double the capacity - Amortized Analysis + + self.A[self.n] = ele + self.n += 1 + + def _resize(self, new_cap): + + B = self.make_array(new_cap) + + for k in range (self.n): + B[k] = self.A[k] + + self.A = B + self.capacity = new_cap + + + def make_array(self, new_cap): + + return (new_cap * ctypes.py_object)() + + +arr = DynamicArray() + +arr.append(1) +print(len(arr)) +print(f"capacity 1: {arr.capacity}") + +arr.append(2) +print(len(arr)) +print(arr[0]) +print(arr[1]) +print(f"capacity 2: {arr.capacity}") + +arr.append(3) +print(f"Length: {len(arr)}") +print(arr[0]) +print(arr[1]) +print(f"capacity 3: {arr.capacity}") + +print() +print("### How to use `sys.getsizeof()` to get an estimate of the memory usage of the `DynamicArray`? ###") +print() + +import sys + +# Assuming the DynamicArray class is defined as before +dynamic_array = DynamicArray() + +# Append some elements to the array +for i in range(100): + dynamic_array.append(i) + +# Get the size of the DynamicArray object in bytes +size_of_dynamic_array = sys.getsizeof(dynamic_array) +print("Size of DynamicArray:", size_of_dynamic_array, "bytes") + +print() +print ("### How to use `tracemalloc` to get an estimate of the memory usage of the `DynamicArray`? ###") +print() + +import tracemalloc + +# Assuming the DynamicArray class is defined as before +dynamic_array = DynamicArray() + +# Enable tracing +tracemalloc.start() + +# Append some elements to the array +for i in range(100): + dynamic_array.append(i) + +# Measure memory usage after appending elements +snapshot = tracemalloc.take_snapshot() +top_stats = snapshot.statistics("lineno") + +for stat in top_stats[:10]: + print(stat) + +# Disable tracing +tracemalloc.stop() + diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-assert.py new file mode 100644 index 0000000..6c65157 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-assert.py @@ -0,0 +1,98 @@ +# def anagram(s1, s2): +# """ +# Problem: Anagram Check + +# Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + +# For example: +# "public relations" is an anagram of "crap built on lies." +# "clint eastwood" is an anagram of "old west action" + +# **Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** +# """ +# s1 = s1.replace(' ', '').lower() +# s2 = s2.replace(' ', '').lower() +# return sorted(s1) == sorted(s2) + + +# def test_anagram(): +# # Test the function for various inputs +# assert anagram('go go go', 'gggooo') == True +# assert anagram('abc', 'cba') == True +# assert anagram('hi man', 'hi man') == True +# assert anagram('aabbcc', 'aabbc') == False +# assert anagram('123', '1 2') == False +# print("ALL TEST CASES PASSED") + + +# if __name__ == '__main__': +# # Run the tests +# test_anagram() +# print("All tests passed!") + + +# from nose.tools import assert_equal + +# def anagram(s1, s2): +# """ +# Problem: Anagram Check + +# Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + +# For example: +# "public relations" is an anagram of "crap built on lies." +# "clint eastwood" is an anagram of "old west action" + +# **Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** +# """ +# s1 = s1.replace(' ','').lower() +# s2 = s2.replace(' ','').lower() +# return sorted(s1) == sorted(s2) + +# def test_anagram(): +# # Test the function for various inputs +# assert_equal(anagram('go go go','gggooo'),True) +# assert_equal(anagram('abc','cba'),True) +# assert_equal(anagram('hi man','hi man'),True) +# assert_equal(anagram('aabbcc','aabbc'),False) +# assert_equal(anagram('123','1 2'),False) +# print("ALL TEST CASES PASSED") + +# if __name__ == '__main__': +# # Run the tests +# test_anagram() +# print("All tests passed!") + +from nose.tools import assert_equal + +def anagram(s1, s2): + """ + Problem: Anagram Check + + Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + + For example: + "public relations" is an anagram of "crap built on lies." + "clint eastwood" is an anagram of "old west action" + + **Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** + """ + s1 = s1.replace(' ','').lower() + s2 = s2.replace(' ','').lower() + return sorted(s1) == sorted(s2) + +class AnagramTest(object): + + def test(self,sol): + assert_equal(sol('go go go','gggooo'),True) + assert_equal(sol('abc','cba'),True) + assert_equal(sol('hi man','hi man'),True) + assert_equal(sol('aabbcc','aabbc'),False) + assert_equal(sol('123','1 2'),False) + print("ALL TEST CASES PASSED") + +if __name__ == '__main__': + # Run Tests + t = AnagramTest() + t.test(anagram) + print("All tests passed!") \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-doctest.py new file mode 100644 index 0000000..0e129db --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-doctest.py @@ -0,0 +1,26 @@ +def anagram(s1, s2): + """ + Problem: Anagram Check + + Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + + For example: + "public relations" is an anagram of "crap built on lies." + "clint eastwood" is an anagram of "old west action" + + **Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** + + >>> anagram('go go go', 'gggooo') + True + >>> anagram('abc', 'cba') + True + >>> anagram('hi man', 'Hi man') + True + >>> anagram('aabbcc', 'aabbc') + False + >>> anagram('123', '1 2') + False + """ + s1 = s1.replace(' ','').lower() + s2 = s2.replace(' ','').lower() + return sorted(s1) == sorted(s2) diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-unittest.py new file mode 100644 index 0000000..e197b99 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/01-Anagram-Check/01-anagram-unittest.py @@ -0,0 +1,36 @@ +import unittest + +def anagram(s1, s2): + """ + Problem: Anagram Check + + Given two strings, check to see if they are anagrams. An anagram is when the two strings can be written using the exact same letters (so you can just rearrange the letters to get a different phrase or word). + + For example: + "public relations" is an anagram of "crap built on lies." + "clint eastwood" is an anagram of "old west action" + + **Note: Ignore spaces and capitalization. So "d go" is an anagram of "God" and "dog" and "o d g".** + """ + s1 = s1.replace(' ', '').lower() + s2 = s2.replace(' ', '').lower() + return sorted(s1) == sorted(s2) + +class TestAnagram(unittest.TestCase): + + def test_anagram(self): + # Test the function for various inputs + self.assertEqual(anagram('go go go', 'gggooo'), True) + self.assertEqual(anagram('abc', 'cba'), True) + self.assertEqual(anagram('hi man', 'hi man'), True) + self.assertEqual(anagram('aabbcc', 'aabbc'), False) + self.assertEqual(anagram('123', '1 2'), False) + + def test_anagram_with_spaces(self): + # Test the function with spaces + self.assertEqual(anagram('aabbcc', 'aab bcc'), True) + self.assertEqual(anagram('Hello World', 'World Hello'), True) + self.assertEqual(anagram('Python', ' Java '), False) + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-assert.py new file mode 100644 index 0000000..0ef21aa --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-assert.py @@ -0,0 +1,57 @@ +from nose.tools import assert_equal + +def pair_sum(arr,k): + """ + Problem - Array Pair Sum + + Given an integer array, output all the ***unique*** pairs that sum up to a specific value **k**. + + So the input: + + pair_sum([1,3,2,2],4) + + would return 2 pairs: + + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + """ + if len(arr)<2: + return + + # Sets for tracking + seen = set() + output = set() + + # For every number in array + for num in arr: + + # Set target difference + target = k-num + + # Add it to set if target hasn't been seen + if target not in seen: + seen.add(num) + + else: + # Add a tuple with the corresponding pair + output.add( (min(num,target), max(num,target)) ) + + print(seen, output) + return len(output) + +class TestPair(object): + + def test(self,sol): + assert_equal(sol([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + assert_equal(sol([1,2,3,1],3),1) + assert_equal(sol([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + #Run tests + t = TestPair() + t.test(pair_sum) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-doctest.py new file mode 100644 index 0000000..6d7089d --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-doctest.py @@ -0,0 +1,24 @@ +def pair_sum(arr,k): + """ + ## Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + pair_sum([1,3,2,2],4) + + would return 2 pairs: + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + + >>> pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10) + 6 + >>> pair_sum([1,2,3,1],3) + 1 + >>> pair_sum([1,3,2,2],4) + 2 + """ + pass + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-unittest.py new file mode 100644 index 0000000..583f794 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/02-Array-Pair-Sum/02-array-pair-sum-unittest.py @@ -0,0 +1,32 @@ +import unittest + +def pair_sum(arr,k): + """ + Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + + pair_sum([1,3,2,2],4) + + would return 2 pairs: + + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + """ + pass + +class TestPair_sum(unittest.TestCase): + + def test_pair_sum(self): + # Test the function for various inputs + self.assertEqual(pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + self.assertEqual(pair_sum([1,2,3,1],3),1) + self.assertEqual(pair_sum([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-assert.py new file mode 100644 index 0000000..8694307 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-assert.py @@ -0,0 +1,36 @@ +from nose.tools import assert_equal + +def finder(arr1,arr2): + """ + Problem - Find the Missing Element + + Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. + + Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array. + + Input: + finder([1,2,3,4,5,6,7],[3,7,2,1,4,6]) + + Output: + 5 is the missing number + + Solution + + Fill out your solution below: + """ + pass + +class TestFinder(object): + + def test(self,sol): + assert_equal(sol([5,5,7,7],[5,7,7]),5) + assert_equal(sol([1,2,3,4,5,6,7],[3,7,2,1,4,6]),5) + assert_equal(sol([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]),6) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + #Run tests + t = TestFinder() + t.test(finder) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-doctest.py new file mode 100644 index 0000000..cc437bd --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-doctest.py @@ -0,0 +1,26 @@ +def finder(arr1,arr2): + """ + Problem - Find the Missing Element + + Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. + + Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array. + + Input: + finder([1,2,3,4,5,6,7],[3,7,2,1,4,6]) + + Output: + 5 is the missing number + + Solution + + Fill out your solution below: + + >>> finder ([5,5,7,7],[5,7,7]) + 5 + >>> finder ([1,2,3,4,5,6,7],[3,7,2,1,4,6]) + 5 + >>> finder ([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]) + 6 + """ + pass diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-unittest.py new file mode 100644 index 0000000..b21aa64 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/03-Finding-the-Missing-Element/03-find-the-missing-element-unittest.py @@ -0,0 +1,42 @@ +import unittest + +def finder(arr1,arr2): + """ + Problem - Find the Missing Element + + Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first array and deleting a random element. Given these two arrays, find which element is missing in the second array. + + Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array. + + Input: + finder([1,2,3,4,5,6,7],[3,7,2,1,4,6]) + + Output: + 5 is the missing number + + Solution + + Fill out your solution below: + """ + pass + +class TestFinder(object): + + def test(self,sol): + # Test the function for various inputs + self.assertEqual(pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + self.assertEqual(pair_sum([1,2,3,1],3),1) + self.assertEqual(pair_sum([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() + + +class TestFinder(object): + + def test(self,sol): + assert_equal(sol([5,5,7,7],[5,7,7]),5) + assert_equal(sol([1,2,3,4,5,6,7],[3,7,2,1,4,6]),5) + assert_equal(sol([9,8,7,6,5,4,3,2,1],[9,8,7,5,4,3,2,1]),6) + print('ALL TEST CASES PASSED') \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-assert.py new file mode 100644 index 0000000..a49eba8 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-assert.py @@ -0,0 +1,27 @@ +from nose.tools import assert_equal + +def pair_sum(arr,k): + """ + Problem - Largest Continuous Sum + + Given an array of integers (positive and negative) find the largest continuous sum. + + Solution + + Fill out your solution below: + """ + pass + +class LargeContTest(object): + def test(self,sol): + assert_equal(sol([1,2,-1,3,4,-1]),9) + assert_equal(sol([1,2,-1,3,4,10,10,-10,-1]),29) + assert_equal(sol([-1,1]),1) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + #Run Test + t = LargeContTest() + t.test(large_cont_sum) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-doctest.py new file mode 100644 index 0000000..6d7089d --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-doctest.py @@ -0,0 +1,24 @@ +def pair_sum(arr,k): + """ + ## Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + pair_sum([1,3,2,2],4) + + would return 2 pairs: + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + + >>> pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10) + 6 + >>> pair_sum([1,2,3,1],3) + 1 + >>> pair_sum([1,3,2,2],4) + 2 + """ + pass + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-unittest.py new file mode 100644 index 0000000..583f794 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/04-Largest-Continuous-Sum/04-largest-continuous-sum-unittest.py @@ -0,0 +1,32 @@ +import unittest + +def pair_sum(arr,k): + """ + Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + + pair_sum([1,3,2,2],4) + + would return 2 pairs: + + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + """ + pass + +class TestPair_sum(unittest.TestCase): + + def test_pair_sum(self): + # Test the function for various inputs + self.assertEqual(pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + self.assertEqual(pair_sum([1,2,3,1],3),1) + self.assertEqual(pair_sum([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-assert.py new file mode 100644 index 0000000..5257209 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-assert.py @@ -0,0 +1,43 @@ +from nose.tools import assert_equal + +def rev_word(s): + """ + Problem - Sentence Reversal + + Given a string of words, reverse all the words. For example: + + Given: + 'This is the best' + + Return: + 'best the is This' + + As part of this exercise you should remove all leading and trailing whitespace. So that inputs such as: + + ' space here' and 'space here ' + + both become: + + 'here space' + + ## Solution + + Fill out your solution below: + """ + pass + +class ReversalTest(object): + + def test(self,sol): + assert_equal(sol(' space before'),'before space') + assert_equal(sol('space after '),'after space') + assert_equal(sol(' Hello John how are you '),'you are how John Hello') + assert_equal(sol('1'),'1') + print("ALL TEST CASES PASSED") + +if __name__ == '__main__': + # Run and test + t = ReversalTest() + t.test(rev_word) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-doctest.py new file mode 100644 index 0000000..6d7089d --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-doctest.py @@ -0,0 +1,24 @@ +def pair_sum(arr,k): + """ + ## Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + pair_sum([1,3,2,2],4) + + would return 2 pairs: + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + + >>> pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10) + 6 + >>> pair_sum([1,2,3,1],3) + 1 + >>> pair_sum([1,3,2,2],4) + 2 + """ + pass + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-unittest.py new file mode 100644 index 0000000..583f794 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/05-Sentence-Reversal/05-sentence-reversal-unittest.py @@ -0,0 +1,32 @@ +import unittest + +def pair_sum(arr,k): + """ + Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + + pair_sum([1,3,2,2],4) + + would return 2 pairs: + + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + """ + pass + +class TestPair_sum(unittest.TestCase): + + def test_pair_sum(self): + # Test the function for various inputs + self.assertEqual(pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + self.assertEqual(pair_sum([1,2,3,1],3),1) + self.assertEqual(pair_sum([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-assert.py new file mode 100644 index 0000000..7b8d653 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-assert.py @@ -0,0 +1,28 @@ +from nose.tools import assert_equal + +def compress(s): + """ + String Compression + + Problem + + Given a string in the form 'AAAABBBBCCCCCDDEEEE' compress it to become 'A4B4C5D2E4'. For this problem, you can falsely "compress" strings of single or double letters. For instance, it is okay for 'AAB' to return 'A2B1' even though this technically takes more space. + + The function should also be case sensitive, so that a string 'AAAaaa' returns 'A3a3'. + """ + pass + +class TestCompress(object): + + def test(self, sol): + assert_equal(sol(''), '') + assert_equal(sol('AABBCC'), 'A2B2C2') + assert_equal(sol('AAABCCDDDDD'), 'A3B1C2D5') + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + # Run Tests + t = TestCompress() + t.test(compress) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-doctest.py new file mode 100644 index 0000000..6d7089d --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-doctest.py @@ -0,0 +1,24 @@ +def pair_sum(arr,k): + """ + ## Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + pair_sum([1,3,2,2],4) + + would return 2 pairs: + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + + >>> pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10) + 6 + >>> pair_sum([1,2,3,1],3) + 1 + >>> pair_sum([1,3,2,2],4) + 2 + """ + pass + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-unittest.py new file mode 100644 index 0000000..583f794 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/06-String-Compression/06-string-compression-unittest.py @@ -0,0 +1,32 @@ +import unittest + +def pair_sum(arr,k): + """ + Problem - Array Pair Sum + + Given an integer array, output all the ** *unique* ** pairs that sum up to a specific value **k**. + + So the input: + + pair_sum([1,3,2,2],4) + + would return 2 pairs: + + (1,3) + (2,2) + + NOTE: FOR TESTING PURPOSES CHANGE YOUR FUNCTION SO IT OUTPUTS THE NUMBER OF PAIRS + """ + pass + +class TestPair_sum(unittest.TestCase): + + def test_pair_sum(self): + # Test the function for various inputs + self.assertEqual(pair_sum([1,9,2,8,3,7,4,6,5,5,13,14,11,13,-1],10),6) + self.assertEqual(pair_sum([1,2,3,1],3),1) + self.assertEqual(pair_sum([1,3,2,2],4),2) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-assert.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-assert.py new file mode 100644 index 0000000..48f259b --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-assert.py @@ -0,0 +1,25 @@ +from nose.tools import assert_equal + +def uni_char(s): + """ + Unique Characters in String + + Problem + Given a string,determine if it is compreised of all unique characters. For example, the string 'abcde' has all unique characters and should return True. The string 'aabcde' contains duplicate characters and should return false. + """ + pass + +class TestUnique(object): + + def test(self, sol): + assert_equal(sol(''), True) + assert_equal(sol('goo'), False) + assert_equal(sol('abcdefg'), True) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + # Run Tests + t = TestUnique() + t.test(uni_char) + print("All tests passed!") + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-doctest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-doctest.py new file mode 100644 index 0000000..ed979f3 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-doctest.py @@ -0,0 +1,18 @@ +def uni_char(s): + """ + Unique Characters in String + + Problem + Given a string,determine if it is compreised of all unique characters. For example, the string 'abcde' has all unique characters and should return True. The string 'aabcde' contains duplicate characters and should return false. + + >>> uni_char('') + True + >>> uni_char('goo') + False + >>> uni_char('abcdefg') + True + """ + pass + + + \ No newline at end of file diff --git a/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-unittest.py b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-unittest.py new file mode 100644 index 0000000..05a024e --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/Array-Sequences-Interview-Questions/07-Unique-Characters-in-String/07-unique-characters-in-string-unittest.py @@ -0,0 +1,22 @@ +import unittest + +def uni_char(s): + """ + Unique Characters in String + + Problem + Given a string,determine if it is compreised of all unique characters. For example, the string 'abcde' has all unique characters and should return True. The string 'aabcde' contains duplicate characters and should return false. + """ + pass + +class TestPair_sum(unittest.TestCase): + + def test_pair_sum(self, sol): + # Test the function for various inputs + self.assertEqual(uni_char((''), True)) + self.assertEqual(uni_char(('goo'), False)) + self.assertEqual(uni_char(('abcdefg'), True)) + print('ALL TEST CASES PASSED') + +if __name__ == '__main__': + unittest.main() diff --git a/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.c b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.c new file mode 100644 index 0000000..fc90f3e --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.c @@ -0,0 +1,11 @@ +// my_library.c + +// Function to add two integers +int add(int a, int b) { + return a + b; +} + +// Function to multiply two doubles +double multiply(double x, double y) { + return x * y; +} diff --git a/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.h b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.h new file mode 100644 index 0000000..b2040a9 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_library.h @@ -0,0 +1,3 @@ +// my_library.h +int add(int a, int b); +double multiply(double x, double y); diff --git a/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_python.py b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_python.py new file mode 100644 index 0000000..5741f13 --- /dev/null +++ b/codebase/python-ds-interview/02-array-sequences/ctypes-make_array/my_python.py @@ -0,0 +1,62 @@ +print("### 1. How to us `ctypes` in Python? ###") +print() + +import ctypes + +# Load the shared library +my_library = ctypes.CDLL('./my_library.so') + +# Specify function return types and argument types +my_library.add.restype = ctypes.c_int +my_library.add.argtypes = [ctypes.c_int, ctypes.c_int] + +my_library.multiply.restype = ctypes.c_double +my_library.multiply.argtypes = [ctypes.c_double, ctypes.c_double] + +# Call the C functions from Python +result_add = my_library.add(10, 5) +result_multiply = my_library.multiply(3.14, 2.0) + +print("Result of add:", result_add) # Output: Result of add: 15 +print("Result of multiply:", result_multiply) # Output: Result of multiply: 6.28 + + +# how to use ctypes to create a C-style array in Python + +print() +print("### 2. How to use ctypes to create a C-style array in Python ###") +print() + +# import ctypes + +class DynamicArray(object): + """ + DYNAMIC ARRAY CLASS (Similar to Python List) + """ + + # ... (Other methods and constructor as defined in the initial code) ... + + def make_array(self, new_cap): + return (new_cap * ctypes.py_object)() + +# Creating an instance of DynamicArray +dynamic_array = DynamicArray() + +# Using make_array to create a new array +new_capacity = 10 +new_array = dynamic_array.make_array(new_capacity) + +# The new_array is a dynamic array with a capacity of 10. +# It can store Python objects, similar to a Python list. +# However, it's not directly accessible as a Python list, and you need to work with it using ctypes or other low-level approaches. + +# For example, you can store values in the new array using ctypes: +for i in range(new_capacity): + new_array[i] = i * 2 + +# Accessing elements in the new array: +for i in range(new_capacity): + print(new_array[i]) + +# Note: This new_array is a C-style array and not directly usable as a Python list. +# If you want a dynamic array similar to Python's list, you should use the DynamicArray class and its append method as described in the initial code. diff --git a/codebase/python-ds-interview/Readme.md b/codebase/python-ds-interview/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/imgs/.DS_Store b/imgs/.DS_Store new file mode 100644 index 0000000..0f837be Binary files /dev/null and b/imgs/.DS_Store differ diff --git a/imgs/Readme.md b/imgs/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/imgs/py-ds/02-big-o-notion.png b/imgs/py-ds/02-big-o-notion.png new file mode 100644 index 0000000..66accfb Binary files /dev/null and b/imgs/py-ds/02-big-o-notion.png differ diff --git a/index.js b/index.js new file mode 100644 index 0000000..e69de29 diff --git a/index.py b/index.py new file mode 100644 index 0000000..c7dedbf --- /dev/null +++ b/index.py @@ -0,0 +1,24 @@ +def solution(inputArray): + def is_one_char_apart(str1, str2): + diff_count = 0 + for c1, c2 in zip(str1, str2): + if c1 != c2: + diff_count += 1 + if diff_count > 1: + return False + return diff_count == 1 + + def backtrack(index): + if index == len(inputArray): + return True + + for i in range(index, len(inputArray)): + inputArray[index], inputArray[i] = inputArray[i], inputArray[index] + if index == 0 or is_one_char_apart(inputArray[index - 1], inputArray[index]): + if backtrack(index + 1): + return True + inputArray[index], inputArray[i] = inputArray[i], inputArray[index] # Backtrack + return False + + return backtrack(0) +