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
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?
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.
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.
THIS IS GENIUS ty my man 🤠
Glad it was helpful!!!
piece of art... i still try to understand the solution. what is time complexity of this solution?
O(n+m). description contains the details
Easy to follow & Simple. Keep up the good work bro!!!
Thanks for the kind words!!! Glad you liked it 😀
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)
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.
No, both have same run time, not much difference. Try to check for any logical errors in the code
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)
check the initialization to avoid runtime error, it's n+2
please suggest some books to solve problems like you
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
why dont we take simply [0] * (n ) because it will have array on n elements
we need additional space to avoid index error
is there a name for this strategy and when should we use this ?
there is no specific name for this, we just build our logic based on the problem given
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
kindly trace the problem with the solution with pen and paper, it will help to understand the working of the logic
can you provide solution in c++
@@ashwinvarma9349 thank you sir
@@sameerkaushik537 You r welcome!
arr[b+1] -= k ? can tell me why we do that
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
@@HackersRealm is that prefix sum algorithm ?
@@AkshaySingh-qs2qm yes
@@HackersRealm This comment finally made this make sense thank you!
you can activate automatic translation in the video?
For subtitles?
@@HackersRealm Correct
@@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
The automatic translation is automatically published by youtube after some time. It's already enable only