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)

КОМЕНТАРІ • 87

  • @rohankherath
    @rohankherath Рік тому +5

    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)

  • @kuraddohikari
    @kuraddohikari 3 роки тому +1

    Thanks! Great practice

  • @dhansraj7345
    @dhansraj7345 2 роки тому +6

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

  • @vedantx-b2986
    @vedantx-b2986 3 роки тому +5

    Thx for this video

  • @babusartop8638
    @babusartop8638 2 роки тому +33

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

  • @sandeshvora
    @sandeshvora 3 роки тому +29

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

  • @manan3434
    @manan3434 2 роки тому +11

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

    • @humanhelperorganization3910
      @humanhelperorganization3910 2 роки тому +5

      def palindrom(s):
      return "Yes it is palindrom" if s[::-1]==s else "not a palindrom"

    • @humanhelperorganization3910
      @humanhelperorganization3910 2 роки тому

      if we write Madam , it returns False, Very case sensitive bro, so here we convert to lower( ) first then run. will it be okay?

    • @noxnpc
      @noxnpc Рік тому

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

    • @raunaktamang8309
      @raunaktamang8309 Рік тому

      @@noxnpc still nlog time complexity if you can do it by converting that will take long which significantly very optimised

  • @ReflectingMe2024
    @ReflectingMe2024 2 роки тому +12

    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)

    • @srdjan780
      @srdjan780 2 роки тому +1

      I think the idea is not to use min/max method, but yeah, for isnt that needed.

  • @amritanjanthakur6510
    @amritanjanthakur6510 2 роки тому +5

    But it said to write a function to sort not lib function..l.sort() is method of a list

  • @nishikanta200
    @nishikanta200 2 роки тому +3

    Thanks a lot for video. I refreshed so many concepts

  • @romkainmotion
    @romkainmotion 2 роки тому

    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.

    • @srdjan780
      @srdjan780 2 роки тому

      this only gives you odd numbers, not prime numbers.

    • @romkainmotion
      @romkainmotion 2 роки тому

      @@srdjan780 damn, you're right :D failed on first question :)

  • @esakkiyae761
    @esakkiyae761 3 роки тому +4

    explain in 5th question sir... I understand logic of slice operations.. But output?

    • @DonSaile
      @DonSaile 2 роки тому +1

      he just forgot to put it and somehow Google prints the result anyways.
      In real Python code you SHOULD write the print() func

  • @jimpauls7765
    @jimpauls7765 Рік тому

    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)

  • @pranjalsharma8798
    @pranjalsharma8798 2 роки тому +8

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

  • @GiorgosKimparis
    @GiorgosKimparis Місяць тому

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

  • @chintucchintu9703
    @chintucchintu9703 3 роки тому +2

    can you pls provide link for colab

  • @vaibhavkulkarni7398
    @vaibhavkulkarni7398 3 роки тому +2

    Osm Video bro

  • @shantanuroy103
    @shantanuroy103 3 роки тому +3

    List in reverse :
    for i in range(len(input_list)-1,-1,-1) :
    reverse_list.append(input_list[i])
    print(reverse_list)

  • @naveenkumarg3015
    @naveenkumarg3015 2 роки тому +1

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

  • @EveryThingOfficial1
    @EveryThingOfficial1 2 роки тому +8

    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)

    • @vaibhavverma1340
      @vaibhavverma1340 2 роки тому

      For i in range(2, num) what is the range of i ? please explain this for loop

  • @dhansraj7345
    @dhansraj7345 2 роки тому +2

    Great, thanks for the video

  • @Evanschengetaindoro0
    @Evanschengetaindoro0 Рік тому

    Good one💯

  • @saikatghosh1430
    @saikatghosh1430 2 роки тому

    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 ?

  • @memeline7015
    @memeline7015 Рік тому

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

  • @monicka4563
    @monicka4563 2 роки тому

    You could just use this instead of the palindrome one:
    def palindrome(word):
    return word[::-1] == word

  • @AdknowledgeIG97
    @AdknowledgeIG97 3 роки тому +1

    For SDE 1 role, can we use Python to solve

  • @nikunjrana5439
    @nikunjrana5439 2 роки тому +1

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

  • @enesuguroglu3542
    @enesuguroglu3542 2 роки тому +3

    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)

    • @humanhelperorganization3910
      @humanhelperorganization3910 2 роки тому

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

    • @quantadotonium3654
      @quantadotonium3654 Рік тому +1

      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.

  • @2mahender
    @2mahender 2 роки тому

    can u please share that google drive doc you have shown with answers

  • @ishwaryasagar9139
    @ishwaryasagar9139 2 роки тому +1

    Very very small letters.... Not visible at all.... Plz do lil bigger so that it will good for us to view

  • @ashwinvijay373
    @ashwinvijay373 3 роки тому +1

    for x in range(1,101):
    if x % 10 in (1,3,5,7,9):
    print(x)

    • @noobmaster-qw7mw
      @noobmaster-qw7mw 3 роки тому +4

      if what you are trying to achieve is printing primes, then this logic is not correct. For eg. 99 % 10 will give you 9.

    • @anveshreddy1918
      @anveshreddy1918 3 роки тому

      Right approach but should not include 9 as it isn't a prime and 2 shld be added

    • @pavansainekkala561
      @pavansainekkala561 2 роки тому

      The written code prints odd numbers between 0 and 101 but not all the primes

  • @vedanthasm2659
    @vedanthasm2659 2 роки тому +1

    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.

  • @nikhilnoona9197
    @nikhilnoona9197 2 роки тому

    Should we be using recursion for fibonacci?

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      bro he has used count > 1 to see duplicate but why he used set ??

  • @surajsahoo649
    @surajsahoo649 2 роки тому

    Developer questions or production support questions?

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      bro he has used count > 1 to see duplicate but why he used set ??

  • @ravishkhullar6717
    @ravishkhullar6717 2 роки тому +5

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

    • @humanhelperorganization3910
      @humanhelperorganization3910 2 роки тому +1

      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

  • @humanhelperorganization3910
    @humanhelperorganization3910 2 роки тому

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

  • @huesOfEverything
    @huesOfEverything Рік тому

    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

  • @kamalkishoremahato2673
    @kamalkishoremahato2673 3 роки тому +1

    Sir ...could u please tell me which compiler do u use here ??

  • @swapneelw
    @swapneelw 2 роки тому +1

    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:

    • @natemillner7199
      @natemillner7199 2 роки тому

      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?

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      @@natemillner7199 bro he has used count > 1 to see duplicate but why he used set ??

  • @RoyalSuperCell
    @RoyalSuperCell 3 місяці тому

    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]

  • @sachinchandanshiv7578
    @sachinchandanshiv7578 Рік тому

    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]

    • @rahulmittal116
      @rahulmittal116 Рік тому

      Use this - lst2 =lst1.copy(); and then append to lst2. it will not append to lst1

  • @kartikdayal8410
    @kartikdayal8410 2 роки тому

    why in range is given (2, num) the range as been give from 100 -200;😏😏

    • @chandushekhar3958
      @chandushekhar3958 Рік тому

      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)

  • @prathameshvaidya3508
    @prathameshvaidya3508 2 роки тому +3

    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)

  • @swethadharmappa
    @swethadharmappa Рік тому

    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)

  • @manikandans2923
    @manikandans2923 2 роки тому

    1st problom
    For i in range (100,200):
    If i%2==1:
    Print(i)
    It's also CRT or not??

  • @Vikrantsingh-sr4wi
    @Vikrantsingh-sr4wi Рік тому

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

  • @100daychallange5
    @100daychallange5 2 роки тому +3

    Tell me this is joke. No way somebody ask you this question on intervy for python junior developer jobs??

  • @arunkumarn8710
    @arunkumarn8710 3 роки тому

    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

  • @sangeethak725
    @sangeethak725 Рік тому

    Writ a program to extact the digit?
    a="1w3er5t678"
    b= list(filter(lambda i:i.isdigit(),a))
    str="".join(b)
    print(str)