Top 15 Python Coding Interview Questions with Solutions - Do it Yourself
Вставка
- Опубліковано 3 кві 2020
- More Python coding interview questions here: • Top 10 Python Coding I...
Top 10 Python Coding Interview Questions & Solutions for FAANG: • Top 10 Python Coding I...
Top 15 Python coding interview Questions & Solutions - Do it Yourself
Top 15 Python Programming Questions & Solutions -asked in Amazon, Facebook, Microsoft, Tesla Interviews
How to crack Python Programming test for Amazon?
How to crack Python Programming test for Facebook?
How to crack Python Programming test for Tesla?
1. Write a Python Program to print Prime Numbers between 2 numbers
2. Write a Sort function to sort the elements in a list
3. Write a sorting function without using the list.sort function
4. Write a Python program to print Fibonacci Series
5. Write a Python program to print a list in reverse
6. Write a Python program to check whether a string is a Palindrome or not
7. Write a Python program to print set of duplicates in a list
8. Write a Python program to print number of words in a given sentence
9. Given an array arr[] of n elements, write a Python function to search a given element x in arr[].
10. Write a Python program to implement a Binary Search
11. Write a Python program to plot a simple bar chart
12. Write a Python program to join two strings (Hint: using join())
13. Write a Python program to extract digits from given string
14. Write a Python program to split strings using newline delimiter
15. Given a string as your input, delete any reoccurring character, and return the new string.
Make a copy of the python notebook
SOLUTION HERE: colab.research.google.com/dri...
Bharati DW Consultancy
cell: +1-562-646-6746
email: bharati.dwconsultancy@gmail.com
website: bharatidwconsultancy.blogspot.com
Twitter: @BharatDWCons
UA-cam: BharatiDWConsultancy
Whatsapp: +1-562-646-6746 (+1-56-COGNOS-46)
1.
for i in range(100,201):
y = []
for x in range(2,12):
if i%x == 0:
y.append(1)
else:
y.append(0)
if sum(y)==0:
print("prime number ",i)
Thanks! Great practice
4th answer: Tried in a different way and works
newlist1=[]
for i in range(0,30):
if not newlist1:
newlist1.append(i)
print('first',i)
elif len(newlist1)==1:
print(i+newlist1[0])
newlist1.append(i)
else:
print(newlist1[len(newlist1)-1]+newlist1[len(newlist1)-2])
newlist1.append(newlist1[len(newlist1)-1]+newlist1[len(newlist1)-2])
Thx for this video
Your're not wasting anyone's time -- we all come here to learn so don't skip anything, no matter how minute it is.
TO LEARN AND CRACK COMPETITIVE PROGRAMS
ua-cam.com/channels/yoFQsVztx2oHWq14nY8A6A.html
3rd problem.. Variable name should be maximum.. Right?
Exactly
Questions are okay. But most of the solutions can be further optimised..
For example palindrome can be check while interating string .just check I and n-1-i char ..mis match then false
I don't think reversed would take constant time..
def palindrom(s):
return "Yes it is palindrom" if s[::-1]==s else "not a palindrom"
if we write Madam , it returns False, Very case sensitive bro, so here we convert to lower( ) first then run. will it be okay?
How about this
Def ss(a)
A=[]
B=[]
A.append (a)
B.append(a)
B.reverse()
If A==B:
print("yes")
Elif A!=B:
print("no")
Else:
print("error")
@@noxnpc still nlog time complexity if you can do it by converting that will take long which significantly very optimised
Question on 3rd answer - no need to iterate over the list with a for-loop or did I miss something? Just get the smallest number, append to new, remove from existing and repeat using the while.
data_list = [25, 55, 78, 64, 25, 12, 22, 11, 1, 2, 44, 3, 122, 23, 34]
new_list = []
while data_list:
minimum = min(data_list)
new_list.append(minimum)
data_list.remove(minimum)
new_list.reverse(sort = True)
print(new_list)
I think the idea is not to use min/max method, but yeah, for isnt that needed.
But it said to write a function to sort not lib function..l.sort() is method of a list
Thanks a lot for video. I refreshed so many concepts
some nice questions to play around with shortest or interesnig answer. For example for first question. There is much shorter solution with if statment, and it possible to do it with oneliner: print(*(i for i in range(100, 200) if i % 2 != 0), sep="
") just for fun.
this only gives you odd numbers, not prime numbers.
@@srdjan780 damn, you're right :D failed on first question :)
explain in 5th question sir... I understand logic of slice operations.. But output?
he just forgot to put it and somehow Google prints the result anyways.
In real Python code you SHOULD write the print() func
Just to suggest a fancy solution to Question 8 in 8:10
sentence = "Adeptus Mechanicus. Glory to the Machine God."
space_count = 0
for i in sentence:
if i.isspace() == True:
space_count += 1
word_count = space_count +1
print(word_count)
PALINDROME
s = input()
if s[0:] == s[::-1]:
print("palindrome")
else:
print("not palidrome")
Exactly it is working ✨
not optimised
Very good work. I just to saying that Fibonacci first number is 0
can you pls provide link for colab
Osm Video bro
List in reverse :
for i in range(len(input_list)-1,-1,-1) :
reverse_list.append(input_list[i])
print(reverse_list)
yes this one is also correct, but print(L[::-1]) it will save time bro .
last question:
a='arrrbbb'
b=''
for i in a:
if i not in b:
b=b+i
b
Q1:
For num in range(100, 200) :
Cpt = 0
For i in range(2, num) :
If num % i != 0:
Cpt += 1
If cpt == num - 2:
Print(num)
For i in range(2, num) what is the range of i ? please explain this for loop
Great, thanks for the video
ua-cam.com/channels/yoFQsVztx2oHWq14nY8A6A.html
Good one💯
q.5>
li = [1, 2, 3, 4, 5, 6, 7, 8, 100]
l = li[::-1]
print(l)
this is also show same result ..is that right ?
q1 better solution
for i in range(101,200):
if i %i==0:
print(i)
You could just use this instead of the palindrome one:
def palindrome(word):
return word[::-1] == word
For SDE 1 role, can we use Python to solve
Qus 1:
for x in range(100,200,2):
print(x)
wrong..returning even numbers not prime
Here is alternative for question 3
def sort_list(x):
l = []
k = list(x)
for j in range(0, len(k)):
for i in k:
if i == max(k):
l.append(i)
k.remove(i)
print(l)
ye bhi chlega bro
L = [23,45,10,9,11,66]
final = [ ]
while L :
final.insert(0,max(L))
l.remove(max(L))
print(final)
but
l = [23,45,10,9,11,66]
new = [ [ max(l),l.remove(max(l))]for i in range(len(l))]
print(new)
can we do this? i want in one line answer, but it returns
[[66, None], [45, None], [23, None], [11, None], [10, None], [9, None]]
is it right way to do this????
Okay but you time complexity is O(N^2) , not only solving the problem but also ALWAYS think of how to get the best optimized solution to a given problem.
can u please share that google drive doc you have shown with answers
Very very small letters.... Not visible at all.... Plz do lil bigger so that it will good for us to view
for x in range(1,101):
if x % 10 in (1,3,5,7,9):
print(x)
if what you are trying to achieve is printing primes, then this logic is not correct. For eg. 99 % 10 will give you 9.
Right approach but should not include 9 as it isn't a prime and 2 shld be added
The written code prints odd numbers between 0 and 101 but not all the primes
Hi.
Can you please confirm on the Question No: 14 solution. I think below code also produce the same result, then why you are using.... rstrip() etc.
new_string = "How are you doing"
output = new_string.split()
print(output)
Result = ['How', 'are', 'you', 'doing']
Thank you.
Should we be using recursion for fibonacci?
bro he has used count > 1 to see duplicate but why he used set ??
Developer questions or production support questions?
bro he has used count > 1 to see duplicate but why he used set ??
In 3rd question, it should have been maximum instead of minimum as if x>minimum, minimum should not be equal to x. Please correct me if I am wrong guys !!
name is not matter :
def sort_function(list):
final = [ ]
for i in range(len(list)):
first_elem = list[0]
for num in list:
if num>first_elem:
first_elem = num
final.insert(0,first_elem)
list.remove(first_elem)
return final
for Palindrome :
def palindrome(s):
return "Yes it is palindrome" if s[::-1].lower() ==s.lower() else "not a palindrome"
In 3 it seems he copied the code... the minumum should be maximum for the problem he is trying to solve but good stuff overall for quick revision
Sir ...could u please tell me which compiler do u use here ??
It is a notebook of Google colab
@@madhusudanverma6564 its Jupiter
Use this template for print the questions (Can anybody solve this? pls help)
Enter name:
Enter department:
Enter feedback:
Enter year:
The program should output the result with the entered values
Name:
Department:
Feedback:
Year:
Name = input("enter name")
Depart = input("Enter department:")
feed = input("Enter feedback:")
year = input("Enter year:")
print(f"Name: {Name} Department: {Depart} Feedback: {feed} Year: {year}.")
this what you wanted?
@@natemillner7199 bro he has used count > 1 to see duplicate but why he used set ??
l=[12,43,2,35,354,5,521]
for i in range(0,len(l)):
for j in range(i+1,len(l)):
if l[i]
Hi Sir,
In below code not getting how, lst1 is appended with element 6 when we are appending only lst2 only.
Can you please Clarify, Thanks
lst1=[1,2,3,4,5]
lst2=lst1
lst2.append(6)
print('lst1- ',lst1)
print('lst2- ',lst2)
Output-
lst1- [1, 2, 3, 4, 5, 6]
lst2- [1, 2, 3, 4, 5, 6]
Use this - lst2 =lst1.copy(); and then append to lst2. it will not append to lst1
why in range is given (2, num) the range as been give from 100 -200;😏😏
prime number : a number is said to be prime number if it is divisible by 1 and itself....so (2, num) so here we should be start with range(2 ,num)
What if we use built in fun i.e min() and max() to sort a list
a=[5,1,8,10,3,7,2,4]
b=[]
while a:
minimum = a[0]
for i in a:
if i==max(a):
b.append(i)
a.remove(i)
print(b)
Extra Space you are using.
Last problem can be solved as below:
s="missisippi"
list1=[]
for i in s:
if (i not in list1) or (i==' '):
list1.append(i)
new_s=''.join(list1)
print(new_s)
1st problom
For i in range (100,200):
If i%2==1:
Print(i)
It's also CRT or not??
will return odd numbers not prime
9).Solution
def Search (arr,x):
for i in range(len(arr)):
if arr[i]==x:
return arr[i]
print('Sorry This element is not Given in this array')
list1=[1,2,3,4,5,6,7,8,9,10]
Search(list1,10)
Pardon Sir,
if we can use this code for Solution (9). So that will give us the actual Values that are in the given array. instead of using iloc (Index Location).
Tell me this is joke. No way somebody ask you this question on intervy for python junior developer jobs??
lol true .
This is beginner stuff
Q15:
#given a string , return recurring characters and display new string
s = 'mississippi'
lst = []
for i in s:
if i not in lst:
lst.append(i)
newS = ''.join(lst)
newS
(or)
#given a string , return recurring characters and display new string
s = 'mississippi'
setList = set()
for i in s:
setList.add(i)
newS = ''.join(setList)
newS
Writ a program to extact the digit?
a="1w3er5t678"
b= list(filter(lambda i:i.isdigit(),a))
str="".join(b)
print(str)