Тёмный

Product of array except self | Leetcode  

Techdose
Подписаться 178 тыс.
Просмотров 97 тыс.
50% 1

Опубликовано:

 

28 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 167   
@cronypau9970
@cronypau9970 2 года назад
the cumulative multiplication at 10:41 will be 1 2 6 24
@hari7110
@hari7110 9 месяцев назад
crct bro
@abhid15
@abhid15 Год назад
This is the clearest, most succinct explainer of this problem that I have come across on RU-vid. Kudos.
@adhirajmajumder
@adhirajmajumder 2 года назад
Most understandable approach on RU-vid ... Appreciate your effort and time
@techdose4u
@techdose4u 2 года назад
Thanks 😊
@rynnxj3935
@rynnxj3935 3 года назад
Thanks for you explanation! Although as a beginner I can only roughly understand until 10:00, but I'm gonna save this to my playlist and come back again when I improved myself in the future!
@sapnokiranii
@sapnokiranii 4 года назад
Great explanation, thank you! I cannot come up with such algorithms on my own, I guess I just have to memorize it for interviews.
@techdose4u
@techdose4u 4 года назад
You will get it soon. For the time being, do it as you find comfortable.
@hardikshettigar805
@hardikshettigar805 3 года назад
Hey How has that turned out for you? Are you placed?
@vikasmeena5448
@vikasmeena5448 Год назад
ofc @@hardikshettigar805
@ashishm8850
@ashishm8850 3 года назад
Bhai, solving it in O(1) space was pure genius! It was like watching a thrilling suspense movie. I had solved the mystery to the point that you would you the o/p array in the calculation, but using that extra product variable was genius. Very nice!
@techdose4u
@techdose4u 3 года назад
😀
@ps6846
@ps6846 3 года назад
we have taken output array that is extra space . so space complexity is still O(n)
@pranavsharma7479
@pranavsharma7479 2 года назад
@@ps6846 bro see ques once then say
@md-ayaz
@md-ayaz 2 года назад
Bro, I feel i can solve this question if I have seen this before. First time, it's not possible. I could only come with division solution. Person who can come up with solution is a genius.
@anshumaan1024
@anshumaan1024 9 месяцев назад
@4:18, code for this approach 🙂🙂 *TC-> O(N), SC->O(1) but using division operation* ✅✅ // CODE class Solution { public: vector productExceptSelf(vector& nums) { int n = nums.size(); int p = 1; int countZero = 0; // multiplying the elements, ignoring zero in the multiplication // also counts the number of zeroes for(int i=0; i= 2, then all elements in answer will be zero if(countZero >= 2){ return ans; } for(int i=0; i
@shubhamsonal5871
@shubhamsonal5871 4 года назад
This question came in goldman sachs exam in 2k19
@techdose4u
@techdose4u 4 года назад
Wowww.... That means it's important :)
@shubhamsonal5871
@shubhamsonal5871 4 года назад
@@techdose4u absolutely.
@shubhamsonal5871
@shubhamsonal5871 4 года назад
@@techdose4u please answer my question on one of your videos. Read the first comment and see in the subcomments , my last two comments and approach. Here's the link to your video. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-NWMcj5QFW74.html
@dhruvmaindola673
@dhruvmaindola673 2 года назад
I did come up with my long solution but the last test case was like a millions of 1s and -1s and the time limit exceeded there. Your approach makes a lot of sense. Just clicking in my head. Nice approach and explanation.
@shikujha4141
@shikujha4141 3 года назад
Very smooth explanation. Due to u I m falling in love of dsa .
@rakshith3547
@rakshith3547 4 года назад
Man, finally I understood this problem.. thank you very much
@techdose4u
@techdose4u 4 года назад
Welcome :)
@marhawk6468
@marhawk6468 3 года назад
This video finally helped me understand the solution. Thank you!
@techdose4u
@techdose4u 3 года назад
Welcome :)
@pawanT23
@pawanT23 2 года назад
This is how earning subscribers looks like, great work👏
@nayanabhoj3126
@nayanabhoj3126 4 года назад
Finally, I understood this problem, Thank you for a good explanation. But test cases without zeros are only passed from this approach, can you guide how to handle with zeros in input?
@techdose4u
@techdose4u 4 года назад
I don't remember it now. I will check it.
@rohit8021
@rohit8021 2 года назад
It will manage if 0 present
@neeleshkumar873
@neeleshkumar873 3 года назад
Nailed it man!!, u made me fall in the problem!!
@techdose4u
@techdose4u 3 года назад
Great ❤️
@andersontiban5356
@andersontiban5356 Год назад
Your explanations are clear and easy to understand, thank you!
@OilUp96
@OilUp96 Год назад
Beautifully explained ,I just needed the missing piece of the puzzle and you just provided me with this video thanks a lot
@genericstospecifics1856
@genericstospecifics1856 2 года назад
Like we handled the corner case for 0th index which was final product val, why didn't we handled the last index case explicitly? Sorry If I missed something
@geekystuffs6209
@geekystuffs6209 3 года назад
The last example it should be 24 instead of 12 , the initial o/p array value
@ankurprabhu2547
@ankurprabhu2547 3 года назад
thank god i was so confused because of this and i knew i was right
@dragonite6636
@dragonite6636 2 года назад
yes
@sufiyaniqbal5280
@sufiyaniqbal5280 2 года назад
thanks ,it tooked 1 hr of me to recognise and finally ur cmt helper
@ayushmantiwari6441
@ayushmantiwari6441 2 года назад
just wow explanation
@onlyitj
@onlyitj 3 года назад
Good explanation; although not sure how it can determine anyone’s success on the job? Not sure what’s the point of asking such questions
@techdose4u
@techdose4u 3 года назад
Just a way to filter candidates :)
@toshanverma1084
@toshanverma1084 3 года назад
0(1) space complexity approach was simply awesome
@anmoljaising
@anmoljaising 3 года назад
Awesome!!!! Thank you! I can never think like this!!!
@techdose4u
@techdose4u 3 года назад
Welcome. You can with practice :)
@niraj.suryavanshi_
@niraj.suryavanshi_ Год назад
Great analysis 🤯
@Ramneet04
@Ramneet04 Год назад
Sir so whats the intuition, How should we approach to this question?? The last part is a bit tricky.
@ashishm8850
@ashishm8850 4 года назад
Excellent, as always! Thank you!
@techdose4u
@techdose4u 4 года назад
Welcome :)
@paragroy5359
@paragroy5359 3 года назад
Pretty nice explanation sir....doing a great job
@techdose4u
@techdose4u 3 года назад
Thanks :)
@AvinashJ21
@AvinashJ21 3 года назад
Amazing... Thank you much appreciated.. I dint had idea how to solve thiz problem.. 😢😢
@merabdu
@merabdu Год назад
Here is a pure Javascript solution: var productExceptSelf = function(nums) { let n = nums.length; let output = Array(n).fill(1); for(let i = 1; i < n; i++) { output[i] = output[i - 1] * nums[i - 1]; } let R = 1; for (let i = n - 1; i >= 0; i--) { output[i] *= R; R *= nums[i]; } return output; };
@stupidbutcurious6206
@stupidbutcurious6206 2 года назад
very well explained... i cam across this question while searching for another similar but a littile more complex... can you please help solve.. The Question is:- Given an array of integers of size N, count all possible distinct triplets whose sum is exactly divisible by given integer K. for triplets i, j, k --> i
@hari7110
@hari7110 9 месяцев назад
Thanks bro, understood well😇
@vijeas4679
@vijeas4679 2 года назад
Love the way u optimised it 🙏🙏 and also the way u explain thanks.
@rohandevaki4349
@rohandevaki4349 2 года назад
great explaination
@simranredij1698
@simranredij1698 Год назад
Amazing explanation. it was so so helpful, thanks a lot!
@AyushSharma-ng8oq
@AyushSharma-ng8oq 7 месяцев назад
best explanation
@harshhwardhanrai3716
@harshhwardhanrai3716 3 года назад
vector productExceptSelf(vector& nums); plz can u explain this line of your code , I know java but I'm having difficulty in understanding this.
@techdose4u
@techdose4u 3 года назад
Vector is the return type of function. ProfuctExceptSelf is the function Name and vector inside brackets is receiving the nuns array.
@spetsnaz_2
@spetsnaz_2 4 года назад
Nice question and approach 👍
@techdose4u
@techdose4u 4 года назад
Thanks dude :)
@serenestrolls-d7b
@serenestrolls-d7b 2 года назад
JS solution - const productExceptSelf = function(nums) { let result = [] let product = 1; for (let i = 0; i < nums.length; i++) { if (i > 0) { product *= nums[i-1]; } else { product *= 1; } result[i] = product; } product = 1; for (let i = nums.length - 1; i >= 0; i--) { if (i < nums.length - 1) { product *= nums[i+1]; } else { product *= 1; } result[i] *= product; } return result; };
@VaishnaviNigam
@VaishnaviNigam 3 года назад
AFTER HITTING MY HEAD AND TRYING TO DO IT MYSELF FOR AROUND 1 HOUR AND THEN WATCHING 3 4 YT VIDEOS........FINALLY I GOT TO UNDERSTAND THE LOGIC FROM UR EXPLAINATION.........THANKS SIR..BUT I REALLY FEAR THAT WHY SUCH PREFIX SUM N SUFFIX SUM APPROACHES DONT CLICK MY HEAD.......... DONT KNOW IF SOMEDAY ITLL HAPPEN OR NOT :( :(
@techdose4u
@techdose4u 3 года назад
It will surely happen someday :)
@VaishnaviNigam
@VaishnaviNigam 3 года назад
@@techdose4u HOPING THE SAME 💚
@techdose4u
@techdose4u 3 года назад
Keep practicing
@PrashantSingh-pg9vq
@PrashantSingh-pg9vq 3 года назад
ready for interviews...!!
@krishsingh6122
@krishsingh6122 Год назад
Great explanation!!!
@TheSubhro123
@TheSubhro123 4 года назад
Very good videos sir... Your videos are very helpful to me because you teach better than my college professors ... By the way sir can you give some advice as to how to get good at programming and what to follow to get good at data structure and algorithms and also programming as well ??
@techdose4u
@techdose4u 4 года назад
Yes why not. You can ping me on LinkedIn for your queries.
@TheSubhro123
@TheSubhro123 4 года назад
Sir how to find you on linked in??
@techdose4u
@techdose4u 4 года назад
Link is given on my channel. You can follow that.
@TheSubhro123
@TheSubhro123 4 года назад
OK sir thank you ...
@techdose4u
@techdose4u 4 года назад
Welcome :)
@User-ow7rn
@User-ow7rn 3 года назад
at 4:26,you said 0 case can be avoided by if else ,what if there are more than 1 zeroes ?can i know what will be the if else condition?
@anshumaan1024
@anshumaan1024 9 месяцев назад
if there are more than 1 zero, then all element in the returned array will be zero 🙂🙂, think it yourself here is my code have a look ... . . class Solution { public: vector productExceptSelf(vector& nums) { int n = nums.size(); int p = 1; int countZero = 0; // multiplying the elements, ignoring zero in the multiplication // also counts the number of zeroes for(int i=0; i= 2, then all elements in answer will be zero if(countZero >= 2){ return ans; } for(int i=0; i
@bostonlights2749
@bostonlights2749 4 года назад
This is asked more times than you can imagine
@techdose4u
@techdose4u 4 года назад
Important question!
@Cloud-577
@Cloud-577 2 года назад
thank you that was very helpful
@techdose4u
@techdose4u 2 года назад
Welcome 😀
@CHIRANJIBNANDY1
@CHIRANJIBNANDY1 4 года назад
Awesome explanation.
@techdose4u
@techdose4u 4 года назад
Thanks :)
@ADNANKHAN-jj2jg
@ADNANKHAN-jj2jg 3 года назад
How would the code be different if instead of "except for self" we would have included that position?
@cyruspassi457
@cyruspassi457 4 года назад
Sir,your way of teaching is excellent,but why your subscribers are so less?
@techdose4u
@techdose4u 4 года назад
As more and more people get to know me, our community will keep increasing and hence subscribers :)
@ashishm8850
@ashishm8850 4 года назад
@@techdose4u Amen to that brother!
@nawendusingh2858
@nawendusingh2858 4 года назад
@10:35 sir a little mistake it should be 24 instead of 12. but that's fine we understood it anyways.
@techdose4u
@techdose4u 4 года назад
Nice :)
@timhuang9701
@timhuang9701 3 года назад
Thank your for mentioning this!
@47tejash
@47tejash 3 года назад
Could you please post the explanation for integer to English word problem?
@techdose4u
@techdose4u 3 года назад
I will try that
@maha_349
@maha_349 3 года назад
Sir will u please execute the program for the addition of elements except self
@techdose4u
@techdose4u 3 года назад
👍🏼
@awesomeamazing836
@awesomeamazing836 3 года назад
Please tell me can i use this output array element =(int)(product of all*Math.pow(index element,-1))
@abhishekgupta3698
@abhishekgupta3698 3 года назад
How its space complexity is O(1) ?? when output variable is taking N space
@10ser9
@10ser9 3 года назад
they tell you that the output is not considered when considering space complexity
@pasitopasito1967
@pasitopasito1967 4 года назад
Sir jo last me optimised approach aapne bataya usme bhi toh array le rahe ho cumulative store karne ke lia
@pasitopasito1967
@pasitopasito1967 4 года назад
Phir ye O(1) KAISE HUA???
@techdose4u
@techdose4u 4 года назад
Because the question has mentioned that output array is not counted as extra space. Thats why.
@pasitopasito1967
@pasitopasito1967 4 года назад
Sir, ds/algo ke jab question nahi hote toh kya hume uska answer dekhna chahiye ya sirf just sochna chahiye jab tak nahi hota ????
@techdose4u
@techdose4u 4 года назад
Time dedo sochne ke liye. Par boht jyada time bhi nhi dena chahiye wrna time waste hoga.
@aviligondagowtham1153
@aviligondagowtham1153 4 года назад
Find maximum possible stolen value from houses pls tell this problem as it is an dynamic programming
@techdose4u
@techdose4u 4 года назад
What help do you need here?
@sukiratsingh985
@sukiratsingh985 Год назад
but for left cumulative array complexity is n2???So how O(N)
@yashgoswami5374
@yashgoswami5374 4 года назад
sir I had commented on "last stone weight" video for different approach, please ans
@techdose4u
@techdose4u 4 года назад
Okay will see it.
@pasitopasito1967
@pasitopasito1967 4 года назад
Sir,How do you think like that????
@techdose4u
@techdose4u 4 года назад
It just comes to mind 😅
@jaydeepmahajan6598
@jaydeepmahajan6598 4 года назад
@@techdose4u we are asking how you approach this problem, what are the things which comes into your mind ?
@techdose4u
@techdose4u 4 года назад
First I solved by division method. Then I thought about how I can avoid dividing. What all I need to find output[i]. I figured it out and used extra space and again solved it. Then I wanted to do it without extra space and so again had to figure out how to use method 2 inplace. So, the third approach came and did solve it again 😅
@jaydeepmahajan6598
@jaydeepmahajan6598 4 года назад
@@techdose4u sir , What's your name ? So we can follow you on Instagram or LinkedIn
@techdose4u
@techdose4u 4 года назад
I have link for my LinkedLink page on my channel.
@bholugupta2248
@bholugupta2248 3 года назад
Sir,,,leetcode ki Minimum divisior within a threshold integer ki solution video bnao.na please
@shaikhzaki3358
@shaikhzaki3358 Год назад
I got a question in which one test case is the arr is [1] . What happen
@qazaqempire3828
@qazaqempire3828 Год назад
only after i watched it 3 times i start to get it lol. hello from kazakstan! dont do festivals during pandemic like in march 2021!
@sivaganesh4489
@sivaganesh4489 4 года назад
Nice
@techdose4u
@techdose4u 4 года назад
Thanks :)
@seraj_valley
@seraj_valley 3 года назад
GOAT
@techdose4u
@techdose4u 3 года назад
😁
@cybersecurity2812
@cybersecurity2812 3 года назад
Another method public class Demo { public static void main(String[] args) { int products[] = {1, 2, 3, 4}; int total[] = new int[products.length]; int ct = products.length; for (int i = 0; i < ct; i++) { int r = 1; for (int x = 0; x < ct; x++) { if (x == i) { continue; } r *= products[x]; } total[i] = r; } for (int t = 0; t < ct; t++) { System.out.println(total[t]); } } }
@san-gd3dy
@san-gd3dy 3 года назад
why didn't you use int product in 18th line?
@shuuuuu659fgg
@shuuuuu659fgg Год назад
class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: res = [] prod = 1 for i in range(len(nums)): prod *= nums[i] res.append(prod) prod = 1 for i in range(len(nums)-1, -1, -1): res[i] = res[i-1] * prod prod *= nums[i] res[0] = prod return res nums:[4,3,2,1,2] op: [48,16,24,48,24] expected:[12,16,24,48,24]
@pranshusati5818
@pranshusati5818 Год назад
class Solution { public int[] productExceptSelf(int[] nums) { int [] ans =new int[nums.length]; int product=1; for(int i = 0 ;i0; i--){ ans[i]=ans[i-1]*product; product*=nums[i]; } ans[0]=product; return ans; } }
@aviligondagowtham1153
@aviligondagowtham1153 4 года назад
I have a doubt that u have worked already in product based company..??
@shubhamsonal5871
@shubhamsonal5871 4 года назад
he works at samsung R&D . query answered
@techdose4u
@techdose4u 4 года назад
So fast 🤣
@bholugupta2248
@bholugupta2248 3 года назад
Tech Dose
@techdose4u
@techdose4u 3 года назад
:)
@harvendrasinghrathore2848
@harvendrasinghrathore2848 3 года назад
First find product of all elements Then arr[I]=product/arr[i];
@vasugaur1283
@vasugaur1283 3 года назад
bro plz give solution link to all approaches
@godoffortuneful
@godoffortuneful Год назад
What if input array contains 0
@staybalancedn
@staybalancedn 2 года назад
This gets complex quick, i only understood the first solution.
@bitrish34
@bitrish34 3 года назад
🔥🔥🔥
@techdose4u
@techdose4u 3 года назад
🔥
@MarsTheProgrammer
@MarsTheProgrammer 2 года назад
I have my cs degree and been programming for years, i just cannot for the life of me understand how this works...
@TheDailyProphet789
@TheDailyProphet789 2 года назад
Compile ni ho rhaa,, vector mai prblm bta rha haii
@ankurgupta4696
@ankurgupta4696 4 года назад
but when nums[i] would be 0 the product would be zero and then the whole output would become 0
@ankurgupta4696
@ankurgupta4696 4 года назад
My mistake it works.....
@aryankumar87771
@aryankumar87771 2 года назад
sir why have you written Leetcode like Pornhub logo on thumbnail
@shyamprakashm6325
@shyamprakashm6325 4 года назад
I have solved already this problem.my solution is simple. Step1: find the product of the elements in the array.let say Arr[1,2,3,4].product=4*3*2*1=24 Product=24. Step2: start the loop from 1 to n or 0 to less than n : printf("%d",PRODUCT/arr[i] ) Output[24/1,24/2,24/3,24/4] [24,12,8,6]
@f3-faithfitnessfinance
@f3-faithfitnessfinance 4 года назад
This won't work..
@shyamprakashm6325
@shyamprakashm6325 4 года назад
@@f3-faithfitnessfinance why bro 🙄🙁🙁
@f3-faithfitnessfinance
@f3-faithfitnessfinance 4 года назад
@@shyamprakashm6325 try submitting this bro You will get to know...
@babyhl016
@babyhl016 4 года назад
This works but the question does not allow division
@techdose4u
@techdose4u 4 года назад
The question doesn't allow division method. Even though you use it, you will have to handle many corner cases. Better to do it using multiplication process
@manishnegi7926
@manishnegi7926 3 года назад
vector productExceptSelf(vector& nums, int n) { vector ans(n,1); long long int p1=1,p2=1; for(int i=1;i
@techdose4u
@techdose4u 3 года назад
👍🏼
@deveshkumar2862
@deveshkumar2862 3 года назад
bro can you explain this Approch please
@rajankhunt7002
@rajankhunt7002 2 года назад
like
@Pritamdas-bg7fp
@Pritamdas-bg7fp 4 года назад
Sir samaj me nahi aya.. Sir thoda detail me bataaya
@techdose4u
@techdose4u 4 года назад
It was in detail only.
@Pritamdas-bg7fp
@Pritamdas-bg7fp 4 года назад
@@techdose4u sir i think mera basic strong nahi hai... Sir aap hindi me video banaya na..
@subham-raj
@subham-raj 4 года назад
@@Pritamdas-bg7fp don't be disappointed bro just practice as much as you can. One day these will be easy for you.
@techdose4u
@techdose4u 4 года назад
Just keep practicing....everyone has the potential inside to be good. You too have it.
@Pritamdas-bg7fp
@Pritamdas-bg7fp 4 года назад
@@techdose4u thank you sir...
@SarveshGupta-bu5ho
@SarveshGupta-bu5ho 3 года назад
Sakhti dekho aapke pehle ek bandi ki video thi chhod ke aaya
@Wanderlust1342
@Wanderlust1342 8 месяцев назад
such a a monotonic voice its giving me brain hemorrhage
@ManishGupta-wb2wc
@ManishGupta-wb2wc 2 года назад
very bad explanation.
Далее
Product of Array Except Self - Leetcode 238 - Python
11:54
Jump game | Leetcode #55 | Valley peak approach
12:28
Просмотров 192 тыс.
Купил КЛОУНА на DEEP WEB !
35:51
Просмотров 3,2 млн
Nightmare | Update 0.31.0 Trailer | Standoff 2
01:14
Просмотров 660 тыс.
Valid parenthesis string | Leetcode #678
12:41
Просмотров 52 тыс.
Remove K digits | Build lowest number | Leetcode #402
15:30
Search in rotated sorted array | Leetcode #33
13:52
Просмотров 84 тыс.
Sort colors | Leetcode #75
6:02
Просмотров 86 тыс.
Maximum Sum Circular Subarray | Leetcode #918
14:02
Просмотров 86 тыс.