106 - Array Manipulation | Arrays | Hackerrank Solution | Python

preview_player
Показать описание
⭐️ 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).

Make a small donation to support the channel 🙏🙏🙏:-

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

MrDitkovitch
Автор

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.

sujaikrishnanc
Автор

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.

assortedDreamer
Автор

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

cer_oz
Автор

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)

davidhuang
Автор

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)

zhengxijiang
Автор

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

anirudhjayant
Автор

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

rohitsanwariya
Автор

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.

avinashhemanth
Автор

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

helikopter
Автор

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

kolla_teja
Автор

please suggest some books to solve problems like you

gokuljs
Автор

you can activate automatic translation in the video?

AndresRojas-bmzv
Автор

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

Alphabetagama-qsqm
welcome to shbcf.ru