FIND MISSING NUMBER IN AN ARRAY IN PYTHON

Sdílet
Vložit
  • čas přidán 23. 01. 2020
  • FIND MISSING NUMBER IN AN ARRAY(SUMMATION & X-OR) - PYTHON INTERVIEW QUESTION
    GitHub Link:- github.com/netsetos/python_co...
    ~-~~-~~~-~~-~
    Please watch: "LRU Cache (With Python Code) "
    • LRU Cache Implementati...
    ~-~~-~~~-~~-~

Komentáře • 31

  • @SrikanthDuvvala-iz5tv
    @SrikanthDuvvala-iz5tv Před měsícem +1

    def missing_num(s):
    first=min(s)
    last=max(s)
    for i in range(first,last+1):
    if i not in s:
    print(i)
    s=[1,2,4,5,6,7]
    missing_num(s)

  • @robina4151
    @robina4151 Před 3 lety +8

    Sorry to say bit i think u have complicated it. I used the below:
    a = [9,1,2,4,5,7,8]
    def missing_nos(a):
    a.sort()
    ln_no = a[-1]
    mss_no = []
    for i in range(ln_no+1):
    if i in a:
    pass
    else:
    mss_no.append(i)
    return mss_no
    print(missing_nos(a))
    But nice series.. Thanks!!

  • @soniyashende4560
    @soniyashende4560 Před 3 lety +1

    Could you please explain why the range (1,n+2)

    • @looploop6612
      @looploop6612 Před 7 měsíci

      n is 6 , but we want to a range from 1 to 7.
      range(1,6+2) give a range from 1 to 7

  • @niveaprakash5482
    @niveaprakash5482 Před 3 lety +11

    Simpler Version
    lst=[1,3,5,6,7,8,20]
    def missing_no(lst):
    list1=[]
    for i in range(1,lst[-1]):
    if i not in lst:
    list1.append(i)
    return (list1)
    print(missing_no(lst))

    • @learnvik
      @learnvik Před 2 lety +1

      I like it

    • @shashank10501
      @shashank10501 Před rokem +2

      It is correct but it will fail for less time complexity.

    • @looploop6612
      @looploop6612 Před 7 měsíci

      It looks simple but it is not ideal.
      Time complexity can be very high if running large data.

  • @harikrishnants8545
    @harikrishnants8545 Před 4 lety

    can you please explain line -"14,15" why index is not been read , how come the value is reading there.

  • @mahammadshoyab9717
    @mahammadshoyab9717 Před 3 lety

    Can you post more algorithm based interview questions

  • @sharmishthadevi7637
    @sharmishthadevi7637 Před 3 lety

    Awesome video

  • @rohitk4483
    @rohitk4483 Před 3 lety +2

    I am not getting(1, n+2 )

    • @VishnuVardhan-dc7rt
      @VishnuVardhan-dc7rt Před 4 měsíci

      n means length of the list, the above n is 6
      we need to iterate through 7 , so that n+2 => 6+2 = 8
      **It will only possible when the missing count is 1.
      And the xor method also only possible when the missing count is 1.

  • @mouleaswar5246
    @mouleaswar5246 Před 3 lety +3

    What if we are missing two numbers

    • @gnanaprakash6488
      @gnanaprakash6488 Před 5 měsíci

      a=[1,2,4,6,7,8,10,15]
      n=a[-1]
      for i in range (1,(n+1)):
      if i not in a:
      print(i,end=(","))
      use function also if u need

    • @SqlMonkey
      @SqlMonkey Před měsícem

      arr= [1,2,5,6,7]
      def missing_mul_num(arr):
      all_num = set(range(1,max(arr)+1)) #7
      given_arr = set(arr)
      missing_numbers = sorted(all_num - given_arr)
      return missing_numbers
      missing_mul_num(arr)

  • @kommunagasheshu3601
    @kommunagasheshu3601 Před rokem +1

    n=a[-1] . How is it comes?

    • @sagarbhagat6475
      @sagarbhagat6475 Před rokem

      Basically, a = that array...[1,2,4,5,6,7]
      And a[-1] means last item of that array....is 7
      So a[-1]=n....which is 7
      a[-1] = 7

  • @amarjeetkumarsingh428
    @amarjeetkumarsingh428 Před 4 lety

    How could you tell me how you have taken n=[-1] replay please

    • @nETSETOStECH
      @nETSETOStECH  Před 4 lety +1

      At 6:22 It is n=a[-1], In Python language, we take last number by this reference. Here n=7

  • @techiewithcamera
    @techiewithcamera Před 11 měsíci

    My Solution:
    def missing_num(list1):
    missing_list=[]
    for i in range(list1[0], list1[-1]+1):
    if i not in list1:
    missing_list.append(i)
    return missing_list
    list1=[1, 3, 4, 5, 6, 7]
    missing_num(list1)

  • @vijayekambaram5386
    @vijayekambaram5386 Před 11 měsíci

    n=a[-1] this step is confusing

  • @enjoyfriends873
    @enjoyfriends873 Před 9 měsíci

    Thanks
    import itertools
    a = [1,2,3,6,8]
    b = [*range(1,max(a))]
    print(set(a).symmetric_difference(b))

  • @knowledgepower5192
    @knowledgepower5192 Před 3 měsíci +1

    very irritating music

  • @siddhigolatkar8558
    @siddhigolatkar8558 Před 8 měsíci +1

    import numpy as np
    a = np.array((1,2,4,5,6,7))
    from functools import reduce
    sum_a = reduce(lambda x,y: x+y, a)
    sum_actual = reduce(lambda x,y : x+y, range(8))
    print(sum_actual, sum_a)
    print("The missing number is", sum_actual - sum_a)