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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น •

  • @rohankherath
    @rohankherath 2 ปีที่แล้ว +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)

  • @dhansraj7345
    @dhansraj7345 3 ปีที่แล้ว +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])

  • @sandeshvora
    @sandeshvora 3 ปีที่แล้ว +29

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

  • @ReflectingMe2024
    @ReflectingMe2024 3 ปีที่แล้ว +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.

  • @babusartop8638
    @babusartop8638 3 ปีที่แล้ว +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.

    • @barecodedreamersacademy6147
      @barecodedreamersacademy6147 3 ปีที่แล้ว

      TO LEARN AND CRACK COMPETITIVE PROGRAMS
      th-cam.com/channels/yoFQsVztx2oHWq14nY8A6A.html

  • @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 2 ปีที่แล้ว

      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 2 ปีที่แล้ว

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

  • @gamespauls7765
    @gamespauls7765 2 ปีที่แล้ว

    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)

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

  • @pranjalsharma8798
    @pranjalsharma8798 2 ปีที่แล้ว +8

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

  • @GiorgosKimparis
    @GiorgosKimparis 7 หลายเดือนก่อน

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

  • @Evanschengetaindoro0
    @Evanschengetaindoro0 2 ปีที่แล้ว

    Good one💯

  • @amritanjanthakur6510
    @amritanjanthakur6510 3 ปีที่แล้ว +5

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

  • @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)

  • @RoyalSuperCell
    @RoyalSuperCell 9 หลายเดือนก่อน

    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]

  • @nikunjrana5439
    @nikunjrana5439 2 ปีที่แล้ว +1

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

    • @kanishksharma96
      @kanishksharma96 2 ปีที่แล้ว

      wrong..returning even numbers not prime

  • @esakkiyae761
    @esakkiyae761 3 ปีที่แล้ว +4

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

    • @DonSaile
      @DonSaile 3 ปีที่แล้ว +1

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

  • @vedantx-b2986
    @vedantx-b2986 4 ปีที่แล้ว +5

    Thx for this video

  • @dhansraj7345
    @dhansraj7345 3 ปีที่แล้ว +2

    Great, thanks for the video

  • @naveenkumarg3015
    @naveenkumarg3015 3 ปีที่แล้ว +1

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

  • @nishikanta200
    @nishikanta200 3 ปีที่แล้ว +3

    Thanks a lot for video. I refreshed so many concepts

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

  • @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 ปีที่แล้ว +1

      this only gives you odd numbers, not prime numbers.

    • @romkainmotion
      @romkainmotion 2 ปีที่แล้ว

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

  • @kuraddohikari
    @kuraddohikari 3 ปีที่แล้ว +1

    Thanks! Great practice

  • @memeline7015
    @memeline7015 ปีที่แล้ว

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

  • @enesuguroglu3542
    @enesuguroglu3542 3 ปีที่แล้ว +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 2 ปีที่แล้ว +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.

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

  • @AdknowledgeIG97
    @AdknowledgeIG97 3 ปีที่แล้ว +1

    For SDE 1 role, can we use Python to solve

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

  • @humanhelperorganization3910
    @humanhelperorganization3910 2 ปีที่แล้ว

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

  • @Ishu_daily_chores
    @Ishu_daily_chores 2 ปีที่แล้ว +2

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

  • @vaibhavkulkarni7398
    @vaibhavkulkarni7398 4 ปีที่แล้ว +2

    Osm Video bro

  • @swethadharmappa
    @swethadharmappa 2 ปีที่แล้ว

    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)

  • @sachinchandanshiv7578
    @sachinchandanshiv7578 2 ปีที่แล้ว

    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

  • @chintucchintu9703
    @chintucchintu9703 3 ปีที่แล้ว +2

    can you pls provide link for colab

  • @surajsahoo649
    @surajsahoo649 3 ปีที่แล้ว

    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

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

    • @pavansainekkala999
      @pavansainekkala999 3 ปีที่แล้ว +1

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

  • @2mahender
    @2mahender 2 ปีที่แล้ว

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

  • @prathameshvaidya3508
    @prathameshvaidya3508 3 ปีที่แล้ว +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)

  • @kamalkishoremahato2673
    @kamalkishoremahato2673 3 ปีที่แล้ว +1

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

    • @madhusudanverma6564
      @madhusudanverma6564 3 ปีที่แล้ว

      It is a notebook of Google colab

    • @remrem6681
      @remrem6681 3 ปีที่แล้ว

      @@madhusudanverma6564 its Jupiter

  • @monicka4563
    @monicka4563 2 ปีที่แล้ว

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

  • @swapneelw
    @swapneelw 3 ปีที่แล้ว +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 ??

  • @manikandans2923
    @manikandans2923 2 ปีที่แล้ว

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

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

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

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

  • @kartikdayal8410
    @kartikdayal8410 2 ปีที่แล้ว

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

    • @chandushekhar3958
      @chandushekhar3958 2 ปีที่แล้ว

      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)

  • @sangeethak725
    @sangeethak725 2 ปีที่แล้ว

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