106 - Array Manipulation | Arrays | Hackerrank Solution | Python

Поділитися
Вставка
  • Опубліковано 26 вер 2024
  • ⭐️ Content Description ⭐️
    In this video, I have explained on how to solve array manipulation using prefix sum technique in python. This hackerrank problem is a part of Problem Solving | Practice | Data Structures | Arrays | Array Manipulation and solved in python. The complexity of this solution is O (n+m).
    🔔 Subscribe: bit.ly/hackersr...
    🗓️ 1:1 Consultation with Me: calendly.com/h...
    📷 Instagram: / aswintechguy
    🔣 Linkedin: / aswintechguy
    🎯 GitHub: github.com/asw...
    🎬 Share: • 106 - Array Manipulati...
    😎 Hackerrank problem solving solutions playlist: bit.ly/hackerra...
    🤖 ML projects tutorial playlist: bit.ly/mlprojec...
    🐍 Python tutorial playlist: bit.ly/python3p...
    Make a small donation to support the channel 🙏🙏🙏:-
    🆙 UPI ID: hackersrealm@apl
    💲 paypal: paypal.me/hack...
    #arraymanipulation #howtosolve #hackerrank #hackerranksolutions #hackersrealm #python #arrays #problemsolving #tutorial #algorithms #datastructures #programming #coding #codinginterview #education #aswin

КОМЕНТАРІ • 37

  • @MrDitkovitch65
    @MrDitkovitch65 Рік тому +3

    I sorta understand why we add k at index a and minus k b+1, so that we don't have to do the adding operation which takes O(n) time. But the biggest leap in intuition and logic is the largest element in the array is the running sum. That just doesn't make sense to me. Can you clarify why that is the case?

  • @sujaikrishnanc9646
    @sujaikrishnanc9646 20 днів тому

    I included the print(arr) in the first function. It is causing runtime error. It works if it is excluded. All test cases gets passed.

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

    That's a great solution, and I understand the logic that's great. Sometimes, we are not able to think such logic and use a complex solution, what would you recommend for that.

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

    THIS IS GENIUS ty my man 🤠

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

    piece of art... i still try to understand the solution. what is time complexity of this solution?

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

      O(n+m). description contains the details

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

    Easy to follow & Simple. Keep up the good work bro!!!

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

      Thanks for the kind words!!! Glad you liked it 😀

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

    one question i use the following code to find the max value, and some test cases cannot pass, these are big test cases, can somebody help to point out why?
    for i in range(1,n+2):
    arr[i]=arr[i]+arr[i-1]
    return max(arr)

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

    why list comprehension didn't work for prefix sum it shows time limit exceeded ..? it is faster than normal for loop which is you used to find max element.

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

      No, both have same run time, not much difference. Try to check for any logical errors in the code

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

    This was my first attempt at the problem. It passes 8/15 test cases. Even though It says runtime error, I still do not know what is causing the problem. Is it because of the large numbers in some test cases.
    arr=[0]*(n)
    for a,b,k in queries:
    for i in range(a-1,b,1):
    arr[i]=arr[i]+k
    return max(arr)

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

      check the initialization to avoid runtime error, it's n+2

  • @gokuljs8704
    @gokuljs8704 4 роки тому +2

    please suggest some books to solve problems like you

    • @HackersRealm
      @HackersRealm  4 роки тому

      Just understand the basics of data structures and algorithms, that is enough to solve these problems. You can read cracking the coding interview book for some hard problems

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

    why dont we take simply [0] * (n ) because it will have array on n elements

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

      we need additional space to avoid index error

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

    is there a name for this strategy and when should we use this ?

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

      there is no specific name for this, we just build our logic based on the problem given

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

    what i dont understand is how come it's a 0 in the array and yet you are saying it's 200 and 200 in their spot! The printout clearly states 0s... how are the tests even passing :(
    Can someone give a bit more explanation, because looks like magic to me haha

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

      kindly trace the problem with the solution with pen and paper, it will help to understand the working of the logic

  • @sameerkaushik537
    @sameerkaushik537 4 роки тому +1

    can you provide solution in c++

  • @AkshaySingh-qs2qm
    @AkshaySingh-qs2qm 3 роки тому

    arr[b+1] -= k ? can tell me why we do that

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

      To balance the element that we added before. Remember we need to only add the element for a particular range, that's why after that range, we are negating

    • @AkshaySingh-qs2qm
      @AkshaySingh-qs2qm 3 роки тому

      @@HackersRealm is that prefix sum algorithm ?

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

      @@AkshaySingh-qs2qm yes

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

      @@HackersRealm This comment finally made this make sense thank you!

  • @AndresRojas-bm2zv
    @AndresRojas-bm2zv 4 роки тому

    you can activate automatic translation in the video?

    • @HackersRealm
      @HackersRealm  4 роки тому

      For subtitles?

    • @AndresRojas-bm2zv
      @AndresRojas-bm2zv 4 роки тому

      @@HackersRealm Correct

    • @AndresRojas-bm2zv
      @AndresRojas-bm2zv 4 роки тому

      @@HackersRealm It generally appears in the settings icon automatically translate in your videos is not so I cannot translate it to either the English language or my language, which in this case is Spanish

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

      The automatic translation is automatically published by youtube after some time. It's already enable only