Python Coding Interview Preparation - For Beginners

preview_player
Показать описание
In this video I'll be doing some coding interview preparation by answering an fairly easy python programming problem. This is meant to help you prepare for your coding interviews!

Use the code "techwithtim" for 15% off!!

◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python

◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡


Tags:
- Tech With Tim
- Python Tutorials
- Python Coding Interview
- Coding Interview Python
- Python Coding Interview Prep
- Interview Prep

#Python #CodingInterviewPrep
Рекомендации по теме
Комментарии
Автор

Thank you my friend for this information

nizaranyonemos
Автор

I would use generators for this:

def iterFib():
yield 0
yield 1
first, second = 0, 1
while True:
first, second = second, first + second
yield second

def getNthFib(n):
fib_seq = iterFib()
for _ in range(n-1):
next(fib_seq)
return next(fib_seq)

malmiteria
Автор

Isn’t there a way to solve in constant time using Binet’s formula?

jacobbringham
Автор

Dude... You're blowing ma mind with that recursion....🤐

gingerboy
Автор

Both solutions are kinda bad, instead of doing recursion and filling the stack and calling a lot of functions which is expensive in time you could just do it iteratively, which is a lot faster, doesn't put anything on the stack, and has constant memory

andrewbarzu
Автор

I did it with a list and a for loop in the most simple way possible but I forgot about the odd case where n is 0, 1 or 2 xd

kuchigyz
Автор

11:37 I always avoid the "in" statement as a it is very slow because it has to check every instance. It would be much more efficient to use a try except block instead. try: return calculated[n] except: (something)

paulschmidt
Автор

1st case without storing values runs in O(2^n), However 2nd case in O(n). But we can achieve O(n) without using hash table, But using tuples, It is followed as:-
Def Good_fibonacci(n) :
If n<=1:
Return (n, 0)
Else:
a, b=Good_fibonacci(n-1)
Return a+b, a
In this case, function has been called recursively for one time for one operation which eliminates O(2^n). Hence, it runs with O(n)

mandeepubhi
Автор

It's contra to pep8 to put a space around the equals when assigning an attribute in a function. Tut, tut.

davidmurphy
Автор

why would you use recursion?

if n==2:
return 1;
elif n==1

return 0;

int prev = 0;
int curr = 1;
for i in range(1, n):
int next = curr + prev;
prev = curr;
curr = next;


return curr;

does the job just fine and I assume it's way faster

jupahe
Автор

I have never done any coding before but i am really interested in it! Can anyone tell me some websites that are for total nubes?

marilynbrazzell
Автор

No need to cover fib(3) in the if part, 0+1=1 ;)

SybotLV
Автор

Was that a hash table which you used in your 2nd code which executes your code more faster?

pushpajitbiswas
Автор

Time complexity of this method is exponential. Avoid recursion when you can solve the problem in an iterative fashion.

hasantao
Автор

or you could do this

def Fibonacci(n):
fibNum = [0, 1]

if n <= 1:
fibNum = [0]

while len(fibNum) != n and n >= 3:
fibNum.append(fibNum[-2] + fibNum[-1])

return fibNum

Though this is longer.

kaushallyadealwis
Автор

Literally me seeing this video after watchin algo expert add

ashvinpkumar
Автор

What's the advantage over premium leetcode + free YouTube problem solving channels ?

andrerodriguez
Автор

hey tim, i tried solving the question befor watching your/ the solution. this is what i came up with:


def getNthFib(n):
list = [0, 1]
for number in range(2, n):
fib_number = list[number-1] + list[number-2]
list.append(fib_number)

print(f'Input: {n}')
print(f'Output: {list[n-1]}, {list}')


from my testing it finds the right number and makes the right list. but it failes all the tests :(..

Kirchert
Автор

Does this work?
nlist=[0, 1]
for i in range(10):

adithmanu
Автор

Your solution didnt show the result stored in a list, it still spits out single values

ehizuelenabhulimen