Top 15 Python Coding Interview Questions with Solutions - Do it Yourself

preview_player
Показать описание


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
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

Bharati DW Consultancy
cell: +1-562-646-6746
Twitter: @BharatDWCons
Youtube: 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)

rohankherath
Автор

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:


dhansraj
Автор

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)

ReflectingMe
Автор

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..

manan
Автор

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]<l[j]:
l[i], l[j]=l[j], l[i]
print(l)


Without Using Sort Functiion

RoyalSuperCell
Автор

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)

gamespauls
Автор

3rd problem.. Variable name should be maximum.. Right?

sandeshvora
Автор

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)

EveryThingOfficial
Автор

Your're not wasting anyone's time -- we all come here to learn so don't skip anything, no matter how minute it is.

babusartop
Автор

Very good work. I just to saying that Fibonacci first number is 0

GiorgosKimparis
Автор

List in reverse :
for i in range(len(input_list)-1, -1, -1) :

print(reverse_list)

shantanuroy
Автор

PALINDROME

s = input()
if s[0:] == s[::-1]:
print("palindrome")
else:
print("not palidrome")

pranjalsharma
Автор

q1 better solution
for i in range(101, 200):
if i %i==0:
print(i)

memeline
Автор

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="\n") just for fun.

romkainmotion
Автор

Qus 1:
for x in range(100, 200, 2):
print(x)

nikunjrana
Автор

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 ?

saikatghosh
Автор

Thanks a lot for video. I refreshed so many concepts

nishikanta
Автор

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)

enesuguroglu
Автор

last question:
a='arrrbbb'
b=''
for i in a:
if i not in b:
b=b+i
b

naveenkumarg
Автор

for Palindrome :
def palindrome(s):
return "Yes it is palindrome" if s[::-1].lower() ==s.lower() else "not a palindrome"

humanhelperorganization