jmportilla / python-for-algorithms--data-structures--and-interviews Goto Github PK
View Code? Open in Web Editor NEWFiles for Udemy Course on Algorithms and Data Structures
Files for Udemy Course on Algorithms and Data Structures
This is about Array Pair Sum.ipynb
in Array Sequence Interview Questions - PRACTICE
. This notebook is part of lectures 53 and 54.
Though the notebook is located in the PRACTICE folder, I want to point out that the function returns an incorrect result for pair_sum([1,3,2,2],3)
.
pair_sum([1,3,2,2],3)
is 2
.pair_sum([1,3,2,2],3)
should be 1
since (1,2)
appears twice ((1,2)
, (2,1)
) but unique sums are searched for.Maybe this should be added to the list of test cases.
Just to make sure all is clear and nobody gets the wrong idea while solving this problem.
In folder:
Algorithm Analysis and Big O
In notebook:
Big O Examples .ipynb
In Section:
Calculating Scale of Big-O
Type here:
"If you've taken a calculus class before, this will reminf you of taking limits towards infinity."
This repository makes use of very long filepaths/filenames. Subfolders state the full name of the module and then repeat the name in the interview questions section, i.e.:
Python-for-Algorithms--Data-Structures--and-Interviews
/Stacks, Queues and Deques
/Stacks, Queues, and Deques Interview Problems
Implement a Queue -Using Two Stacks - SOLUTION.ipynb
When trying to clone the whole repository to my Windows machine, it is not possible to complete because the filenames of some folders are too long when stored in the typical folder I use for Github repos (which has a not-too-deep path of ~30 characters itself).
Consider renaming folders to make it possible to clone the entire repository instead of manually downloading .pynb files one by one.
Wrong issue, I was looking at an edited version of the notebook. Apologise for the noise.
It is possible to write a function that passes all current tests in the Balanced Parentheses Check problem but that fails with an IndexError if a closing parentheses occurs when there is an empty stack.
Adding this test case handles the issue:
assert_equal(sol('][[[]])]'),False)
AssertionError Traceback (most recent call last)
in ()
13 # Run Tests
14 t = AnagramTest()
---> 15 t.test(anagram)
in test(self, sol)
4
5 def test(self,sol):
----> 6 assert_equal(sol('go go go','gggooo'),True)
7 assert_equal(sol('abc','cba'),True)
8 assert_equal(sol('hi man','hi man'),True)
/anaconda3/lib/python3.6/unittest/case.py in assertEqual(self, first, second, msg)
827 """
828 assertion_func = self._getAssertEqualityFunc(first, second)
--> 829 assertion_func(first, second, msg=msg)
830
831 def assertNotEqual(self, first, second, msg=None):
/anaconda3/lib/python3.6/unittest/case.py in _baseAssertEqual(self, first, second, msg)
820 standardMsg = '%s != %s' % _common_shorten_repr(first, second)
821 msg = self._formatMessage(msg, standardMsg)
--> 822 raise self.failureException(msg)
823
824 def assertEqual(self, first, second, msg=None):
AssertionError: False != True
The results for the Nth number in the sequence are not clear, unless the start of the sequence begins with the Nth number of 0, i.e.
N=0, 0
N=1, 1
N=2, 1
N=3, 2
N=4, 3
N=5, 5
N=6, 8
N=7, 13
N=8, 21
N=9, 34
N=10, 55
etc.
The description seems to confuse the Fibonacci sequence with a factorial sequence, when it says:
Remember that a fibonacci sequence: 0,1,1,2,3,5,8,13,21,... starts off with a
base case checking to see if n = 0 or 1, then it returns 1.
Else it returns fib(n-1)+fib(n+2).
This should read:
Remember that a Fibonacci sequence: 0,1,1,2,3,5,8,13,21,... starts off with a
base case checking to see if n = 0 or 1, then it returns n,
else it returns fib(n-1) + fib(n-2).
if n = 0 or 1, then it returns n
(not 1) fib(n-1)+fib(n+2)
, it should be fib(n-1)+fib(n-2)
.Hope this is right and helps to make a correction.
PS, thanks for a great course
I'm not exactly sure this is an issue but I'm going through your Udemy course right now (great course by the way!) and I was wondering about this part.
def __getitem__(self, k):
"""
Return element at index k
"""
if not 0 <= k < self.n:
return IndexError('K is out of bounds!') # Check it k index is in bounds of array
return self.A[k] #Retrieve from array at index k
Is there a particular reason why you use return IndexError
instead of raise IndexError
? I've searched a bit on the internet but cannot find a similar example. I'm only familiar with using raise IndexError
and this is the first time I've seen an error returned like that.
Thanks!
EDIT:
Just noticed a potential typo in your code as I was re-reading my comment.
# Check it k index
^^
# if ?
In folder:
Algorithm Analysis and Big O
In notebook:
Big O Examples .ipynb
Notebook link
In Section:
Calculating Scale of Big-O
Type here:
"If you've taken a calculus class before, this will reminf you of taking limits towards infinity.
###(Correct the spelling of remind)
When I try to download the zipped folder from Github and Extract files -> It gives invalid file Error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.