Lecture 29: Kadane's Algorithm || Prefix and Suffix Sum || Array into 2 equal Sum Subarray

  Рет қаралды 62,351

Coder Army

Coder Army

Күн бұрын

Пікірлер: 210
@CoderArmy9
@CoderArmy9 Жыл бұрын
You Guys are Love❤
@YashSaini007
@YashSaini007 Жыл бұрын
Good Morning Bhaiya ❣️
@Kalamkaar2607
@Kalamkaar2607 Жыл бұрын
@CoderArmy9 is love
@bonkai.movies
@bonkai.movies Жыл бұрын
bhaiya your debugging process in blackboard is making you diffrent then others keep it up BestOluck
@HONESTLYALOK
@HONESTLYALOK Жыл бұрын
Thank you bhaiya
@VivekMishra-yq5us
@VivekMishra-yq5us Жыл бұрын
❤❤
@Updatedknowledge9
@Updatedknowledge9 Жыл бұрын
Bhaiya aap ek baat universal truth hai, ki starting me sab easy lagta hai, fir hard iske baaad, fir se sab easy lagne lagta hai ☺☺☺❤❤❤, main to aise hi feel kar rha hu,
@inspirationalyouthicons4998
@inspirationalyouthicons4998 Жыл бұрын
1:15:03 hw maximum diffrence between two elements:- int maximumdiffrencebetweentwoelements(int arr[],int n){ int suffix[n]; suffix[n-1] = arr[n-1]; for(int i=n-2;i>=0;i--){ suffix[i] = max(suffix[i+1],arr[i]); } int ans = INT_MIN; for(int i=0;i
@Anjali-ty2fk
@Anjali-ty2fk 2 ай бұрын
Aap ek baar iss solution main mistake bta do please int suffix=nums[n-1]; int ans=INT_MIN; for(int i =N-2;i>=0;i--) { suffix=max(nums[i],suffix); ans=max(ans,suffix-nums[i]); } return ans; } return -1;
@ronitapatra
@ronitapatra Ай бұрын
@@Anjali-ty2fk first you have to calcualte the difference then update suffix...otherwise suffix = nums[n-1] will update first...
@ujjwalgaur5460
@ujjwalgaur5460 16 күн бұрын
@@Anjali-ty2fk dont know this method i solved through two pointers mthd#include using namespace std; int main() { int arr[8] = {9, 8, 8, 12, 0, 3, 7, 4}; int s = 0, e = 1; // Start and end pointers int maxdiff = 0; // To store the maximum difference int n = 8; // Size of the array while (e < n) { if (arr[e] > arr[s]) { // Calculate the difference int diff = arr[e] - arr[s]; // Update maxdiff if the current difference is greater if (diff > maxdiff) { maxdiff = diff; } } else { // Move the start pointer to the current end pointer s = e; } // Always move the end pointer forward e++; } cout
@Sajal_Mallick_vlogs
@Sajal_Mallick_vlogs 10 ай бұрын
Day 39/180 done and dusted.... Awesome explanation and exceptional learning.. Thank you bhaiya... #consistency
@imavinashsingh
@imavinashsingh 10 ай бұрын
0:00:01 [Prefix and Suffix Sum] 0:09:50 [Divide Array in two Sub arrays with equal sum ] 0:28:15 [Code Part] 0:35:15 [Largest Sum Contiguous Sub array] 0:47:40 [Kadane's Algorithm ] 1:01:15 [Code Part] 1:03:08 [Max. Difference b/w 2 elements]
@TheSilentObserver30
@TheSilentObserver30 Жыл бұрын
Day 39/180..Growing strong each day and learning new everyday. You are making us consistent and confident. Thank you.
@sarikasaxena5567
@sarikasaxena5567 Жыл бұрын
suffixsum array H.W- vectorsuff(n); suff[n-1]=arr[n-1]; for(int i = n-2;i>=0;i--){ suff[i] = suff[i+1]+arr[i]; }
@rvpool9830
@rvpool9830 Жыл бұрын
To print all subarrays: #include using namespace std; int main(){ int n; cin>>n; int arr[n]; for(int i=0; i> arr[i]; for(int i=0; i
@xavdok
@xavdok 20 күн бұрын
I run your code and I did not get the ans, your code is wrong.
@maroofgpm
@maroofgpm Жыл бұрын
5:08 Likh Diya!! // Homework: Sum of suffix #include #include using namespace std; int main() { int vect[] = {1,2,3,4,5}; int n = 5; for (auto i : vect) { cout
@joydeep-halder
@joydeep-halder Жыл бұрын
5:10 H/W Suffix Sum: suffix[n-1] = arr[n-1] for(int i=n-2; i>=0; --i) { suffix[i] = suffix[i+1] + arr[i] }
@lotifurshabbir7302
@lotifurshabbir7302 Жыл бұрын
why you are giving answer ☹️
@joydeep-halder
@joydeep-halder Жыл бұрын
@@lotifurshabbir7302 To help others 😊
@yashisrivastava6196
@yashisrivastava6196 Жыл бұрын
Will never forget kadane's algorithm now ✨
@VivekMishra-yq5us
@VivekMishra-yq5us Жыл бұрын
Chamk gya hai concept ❤ bhiya
@PandaSingh-o3j
@PandaSingh-o3j 6 ай бұрын
At 48:45 when you add 7 and -5 it is 2 but don't replace it with maxi as maxi contains 7.
@mohdshabaz9675
@mohdshabaz9675 Жыл бұрын
Good explanation of previous videos
@CoderArmy9
@CoderArmy9 Жыл бұрын
Good morning bhai❤
@rockrock350
@rockrock350 Жыл бұрын
never saw this much of dedication
@ajaythedaredevil7220
@ajaythedaredevil7220 5 ай бұрын
Print all Subarray in an array: for i in range(len(res)): for j in range(i+1,len(res)): print(res[i:j])
@PotatoPcGamer01
@PotatoPcGamer01 6 ай бұрын
1:15:03 - Find Largest Difference between 2 elements (HOMEWORK) Time Complexity - O(N) Code : int largestDiff(vector& v, int index) { // 1) initialization : int size = v.size()-1; int difference = 0, ans=INT_MIN, findMax=INT_MIN; // 2) handling edge cases : if(index size) return -1; // 3) find max difference : for(int i = size; i>=index; i--){ findMax = max(findMax, v[i]); difference = findMax - v[i]; ans = max(ans, difference); } return ans; } PS - Suggestions / Replies are welcomed :)
@joydeep-halder
@joydeep-halder Жыл бұрын
9:32 H/W Solution: Print all subarrays: for (int size = 1; size
@joydeep-halder
@joydeep-halder Жыл бұрын
​@@ddoy7378bhai compiler me run karke dekho.
@arjungurjar7702
@arjungurjar7702 7 күн бұрын
1:14:30 int maxDifference(int arr[],int n){ int ans = INT_MIN ; int suffix = 0 ; for(int i = n-1 ; i >=0 ; i--){ suffix = max(suffix , arr[i]); ans = suffix - arr[i]; cout
@RohitCoder
@RohitCoder 11 ай бұрын
at 32:17 why dont we used for(int i=0; i
@bee.eee.
@bee.eee. 5 ай бұрын
n-1 refers to the last element If we take i
@atifmalik8012
@atifmalik8012 3 ай бұрын
59:29 //Kadane's algorithm class Solution { public: // Function to find the sum of contiguous subarray with maximum sum. int maxSubarraySum(vector &arr) { int prefix = 0,MaxSum = INT_MIN; for(int i = 0;i
@AryanShrivastav-n2v
@AryanShrivastav-n2v 20 күн бұрын
Gltt ha bhai..prefix vala line sum kr nicche aayga
@rahulpatil6871
@rahulpatil6871 8 ай бұрын
yaha tk smja ya ni smja ,haan ji bhaiya samj gya😂
@mahuaranu4435
@mahuaranu4435 7 ай бұрын
HW problem ans 1:15:03 int max_difference(int arr[], int n){ int suffix = arr[n-1]; int maxi = INT32_MIN ; int diff = 0; for(int i = n-2; i>=0; i--){ suffix = max(suffix , arr[i]); diff = suffix - arr[i]; maxi = max(maxi , diff); } return maxi; }
@Anonymous_EngineerX
@Anonymous_EngineerX 8 ай бұрын
Kadane's algo to be honest outstanding explanation Thanks bhaijaan
@rohanbarwade578
@rohanbarwade578 5 ай бұрын
best mentor ever
@GayatriShejule-o1k
@GayatriShejule-o1k 24 күн бұрын
Thank you so much sir 🥰
@aayushrajpurohit321
@aayushrajpurohit321 8 ай бұрын
#Chamaka diya bhaiya it was an amazing session.
@saadrml
@saadrml 4 ай бұрын
bhaiya, i think there is slight mistake at 48:54 prefix( mein 2 aane pe) maxi(jo pehle se 7 tha ) usko 2 update nhi karenge , balki 7 hi rehne denge , i hope someone finds its correct 🕊
@_hulk748
@_hulk748 Жыл бұрын
Great Video as always sir🙏🙇‍♂✨💖
@GoogleSoftwareEnginear
@GoogleSoftwareEnginear Жыл бұрын
Bhaiyo itna badiya content bhaiya hme de rhe hai to Subscribe to bnta hai sabhi kre Thank you so much Bhaiya for this amazing DSA series 😊😊👍👍
@atifmalik8012
@atifmalik8012 3 ай бұрын
int equalSubarray(vectorA) { int prefix=0,Totalsum=0; for(int i=0;i
@ankushladani496
@ankushladani496 Жыл бұрын
Done Bhaiya... 39/180 ✅
@OsamaShabih
@OsamaShabih 2 ай бұрын
Chamak gya bhaiya 😊
@Sangi-sj2dy
@Sangi-sj2dy 7 ай бұрын
Simply Awesome
@nitinpal880
@nitinpal880 Жыл бұрын
bhaiya apki vajah se improvement dekh para hu bhot jyada bas revision ka tarika bhi bata do aap
@abhisheksinghmehra9576
@abhisheksinghmehra9576 Жыл бұрын
Amazing explanation bhai as always🔥🔥🔥
@PinkuModi-c6i
@PinkuModi-c6i 6 ай бұрын
bhaiya yaar apne pucha tha ki beech me to ni aa rhe h ad, but aa rhe h-av just aaya jab main 33:15 time stamp pe pahucha aur jaise hi ek question complete hua!!
@heetpatel3037
@heetpatel3037 11 ай бұрын
Chamka bhaiya thank you 👍🏻
@rejaulislam2593
@rejaulislam2593 13 күн бұрын
alhamdulillah lec done
@AnuragSingh-im2md
@AnuragSingh-im2md 17 күн бұрын
Answer for the last question: int n = nums.size(); int suffix = nums[n-1]; int ans = 0; int diff; for(int i = n-2; i>=0; i--){ diff = suffix - nums[i]; ans = max(ans , diff); suffix = max(suffix , nums[i]); } if(ans==0) return -1; else return ans; o(n) T.C
@arpitkhandelwal8280
@arpitkhandelwal8280 6 ай бұрын
amazing lecture bhaiya
@Hiisbnxkskkwl
@Hiisbnxkskkwl Ай бұрын
49:10 time stap pae toh 7 bada ha toh vohi rahega na sir
@ankushladani496
@ankushladani496 Жыл бұрын
Thanks Bhaiya...❤🎉
@Coder-rohits
@Coder-rohits Жыл бұрын
maza aa gaya bhaiya🙌
@neerajrawat4294
@neerajrawat4294 Жыл бұрын
smallest sum contingous subarray is also a variation of kadane's algorithm;
@swapnadip
@swapnadip Жыл бұрын
Good morning Bhaiya 😊🤗🤗
@vermapowerhub
@vermapowerhub Жыл бұрын
Bhaiya aaj aapne day nhi dala video discription m ,ki konsa day h 180 days challenge ka ☺️
@Updatedknowledge9
@Updatedknowledge9 Жыл бұрын
Maza aa gya 😊😊😊😊❤
@atifmalik8012
@atifmalik8012 3 ай бұрын
23:08 //i tried it myslef without watching //In this approch i made two verctors one is prefix other one is suffix //if the perticular index in prefix is same as the element present at index+1 in suffix then return true otherwise false(for all elements) class Solution { public: bool canPartition(vector& nums) { int n = nums.size(); vectorprefix(n); vectorsuffix(n); prefix[0] = nums[0]; for(int i = 1;i=0;i--){ suffix[i] = suffix[i+1] + nums[i]; } for(int i = 0;i
@amritpathak8630
@amritpathak8630 5 ай бұрын
Great effort
@csforcommonsense3360
@csforcommonsense3360 11 ай бұрын
tq for ur lots of efforts
@DesiMrBean7
@DesiMrBean7 Жыл бұрын
Good morning negi bhai❤
@shailjayadav7995
@shailjayadav7995 Жыл бұрын
Good Morning Bhaiya❤
@GOATSOFFOOTBALL
@GOATSOFFOOTBALL 6 ай бұрын
completed,samajh aya
@study-yd6es
@study-yd6es 5 ай бұрын
Amazing Content !!!
@AzeemKhan-oe8rt
@AzeemKhan-oe8rt Жыл бұрын
bhai mujhse homework nhi ho paa rha, jbke me solution sochta rehta hoon 1-2 hours but code me convert ho hi nhi paa rha hai?
@shubhamkumarjha9192
@shubhamkumarjha9192 Жыл бұрын
Good morning Bhaiya..❤️
@CoderArmy9
@CoderArmy9 Жыл бұрын
Good morning bhai❤
@AzeemKhan-oe8rt
@AzeemKhan-oe8rt Жыл бұрын
last wale 2-3 lecture nhi dekh paaya yaha se continue kr skata honnn?????????/ @coder army
@AMITKUMAR-ds4hp
@AMITKUMAR-ds4hp Жыл бұрын
Good morning boss ❤❤❤
@Armoured_Traveller
@Armoured_Traveller Жыл бұрын
Day 39 Bhaiya ek motivational video chahiye apka🎉🎉❤
@sourabhgupta1466
@sourabhgupta1466 7 ай бұрын
best lecture bhai
@Rishi_s.corner
@Rishi_s.corner 11 ай бұрын
chamak gaya bhaiya.
@Codewithkumar-gc1kr
@Codewithkumar-gc1kr 2 ай бұрын
chamak gaya elder brother😊😊 09-Nov-24
@NoorulAbdeenSiddiqui
@NoorulAbdeenSiddiqui 6 ай бұрын
u are the best
@Lifeofmoana22
@Lifeofmoana22 5 ай бұрын
thankyou bhaiyaaa
@Saumyasingh0001
@Saumyasingh0001 11 ай бұрын
Great explanation but i think at 18 min par jo inner loop par 2n kah rahe hai wo 2n nahi hoga waha par dono inner loop milakar n time he chala tho n hona chahiye 😅
@divyanshsharma673
@divyanshsharma673 10 ай бұрын
In worst case, first loop will run n-1 times and the second will 1 time. So n((n-1)+1) = n². It could be for both end so this is why it's 2n.
@akashkewat1219
@akashkewat1219 Жыл бұрын
Completed 😊.
@SnatanGaming
@SnatanGaming 21 күн бұрын
I AM UNABLE TO SOLVE LAST 2 Questions OF THE HOMEWORK SHEET I FOUND THIS LECTURE A BIT TOUGH CONSIDERING ALL THE PREVIOUS LECTURES,BECAUSE IN ALL PREVIOUS HOMEWORK SHEET I ATLEAST THINK OF AN APPROACH TO SOLVE BUT IN THIS LECTURE I AM UNABLE TO DO THAT ALSO.I HAVE TO PRACTICE HARD:(
@joydeep-halder
@joydeep-halder Жыл бұрын
H/W Solutoin: : Maximum prefix sum for a given range vector ans; for (int i = 0; i < Q; ++i) { int start = L[i]; int end = R[i]; int maxPrefix = INT_MIN; int prefix = 0; for (int j = start; j
@utkarshawasthi4791
@utkarshawasthi4791 Жыл бұрын
@jeetusingh6182
@jeetusingh6182 3 ай бұрын
i < Q what does it mean in third line
@TayyabaYasmine
@TayyabaYasmine 3 ай бұрын
Any one know in which lactures he covers the operator overloading and prefis and post fix operator overloading function
@joydeep-halder
@joydeep-halder Жыл бұрын
Good morning bhaiya ❤❤
@CoderArmy9
@CoderArmy9 Жыл бұрын
Good morning bhai❤
@joydeep-halder
@joydeep-halder Жыл бұрын
@@CoderArmy9 😊😊
@parthh1112
@parthh1112 11 ай бұрын
48:55 error 7>2 so no update needed
@karankumar3983
@karankumar3983 Жыл бұрын
Logic behind kadanes algorithm 55:00 to 59:08 kadanes ke pichhe ka kala such 😅
@GaziZai
@GaziZai 11 ай бұрын
Thanks
@nishikantDalal
@nishikantDalal 3 ай бұрын
Maximum Difference between 2 element code: int ans=0; int suffix_max=arr[n-1]; for(int i = n - 2 ; i >= 0 ; i - -){ ans=max(ans , suffix_max - arr[i]); if(arr[i] > suffix_max) suffix_max = arr[i] ; } return ans ;
@jiraiyagaming6491
@jiraiyagaming6491 Жыл бұрын
Good morning 🌞
@CoderArmy9
@CoderArmy9 Жыл бұрын
Good morning bhai❤
@santanudebnath1283
@santanudebnath1283 Жыл бұрын
MAX DIFFERENCE #include using namespace std; int main() { int n,max_diff=0,ans; int arr[10]; coutn; cout=0;i--) { if(arr[i]>prefix) prefix=arr[i]; else { ans=prefix-arr[i]; max_diff=max(ans,max_diff); } } cout
@techmcu
@techmcu 5 ай бұрын
if I'm not wrong bhaiya n-1 indicating last element position
@sarikasaxena5567
@sarikasaxena5567 Жыл бұрын
max difference between 2 element solution: #include using namespace std; int main(){ int n; cin>>n; vector v(n); for(int i =0;i>v[i]; } int ans=0; int suffix=v[n-1]; for(int i = n-2;i>=0;i--){ if(suffix
@diyaseth9688
@diyaseth9688 Жыл бұрын
Thank you bhaiya
@bsufeotxe
@bsufeotxe Жыл бұрын
bhaiya dutch national flag problem bhi samjha do pointer ki help se
@lotifurshabbir7302
@lotifurshabbir7302 Жыл бұрын
1:00:59 vaia here if i wrote that if condition before updating the maxi line, will it work correctly?
@AakashParvani
@AakashParvani Жыл бұрын
Day 39/180 👍✅ Chamak Gaya
@drlovephukn
@drlovephukn Жыл бұрын
Day's 39/180 full power full power ❤❤❤
@asad_iliyas
@asad_iliyas Жыл бұрын
9:29 howework
@prashantsingh3474
@prashantsingh3474 10 ай бұрын
1:15:03 hw maximum diffrence between two elements:- int maximumDifference(vector& n) { int su=INT_MIN , maxi=INT_MIN, sub=; for(int i=n.size()-1;i>=1;i--){ su=max(su, n[i]); sub=su-n[i-1]; maxi=max(sub, maxi); } return maxi; }
@PravilaKumari-uv5be
@PravilaKumari-uv5be Жыл бұрын
Good morning sir
@OnlyPc-c9n
@OnlyPc-c9n 11 ай бұрын
function me 2nd for lop n-1 tak chalege na
@Hermitsays007
@Hermitsays007 5 ай бұрын
homework done suffix[n-1] = arr[n-1]; for(int i = n-2; i>=0; i--){ suffix[i] = suffix[i+1] + arr[i]; }
@SurajKumar-vc4du
@SurajKumar-vc4du Жыл бұрын
radhe radhe
@OmPrakashKewtiya
@OmPrakashKewtiya 3 ай бұрын
Day 29✅
@GopalKumar-xu3iw
@GopalKumar-xu3iw Жыл бұрын
Dya 39/180 complete # hard
@punitpubggaming7531
@punitpubggaming7531 Жыл бұрын
Attendance marked ✅
@rajatjana2513
@rajatjana2513 Жыл бұрын
Day1🙏🙏🙏
@arunrajput8153
@arunrajput8153 Жыл бұрын
Love u bhai
@sahilCSE999
@sahilCSE999 10 ай бұрын
Bhaia 51:58 pe 13 kaise hoga 7+6+2 = 15 hoga n
@vermapowerhub
@vermapowerhub Жыл бұрын
Good morning coders ❤
@Megha3570
@Megha3570 6 ай бұрын
Bhaiya can't we just sort the array first in max difference between 2 elements
@bee.eee.
@bee.eee. 5 ай бұрын
Noo, because the order of element matters, it says the we can only subtract an element from an element which is to it's right side (doesn't matter how far) So yes, if we sort it the order will be neglected and we will basically end up getting Max element - min element which is not the required answer.
@Megha3570
@Megha3570 5 ай бұрын
@@bee.eee. thanks ☺️
@anshikathakur3567
@anshikathakur3567 11 ай бұрын
lecture 29✅
@tanishqdixit6313
@tanishqdixit6313 Жыл бұрын
Day 39/180 completed
Lecture 30: Trapping Rain Water || 3 SUM || 4 SUM
1:14:13
Coder Army
Рет қаралды 44 М.
Prefix Sum Array and Range Sum Queries
7:30
Profound Academy
Рет қаралды 9 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Prefix Sums - Problems, Code in C++ & Python
20:51
Errichto Algorithms
Рет қаралды 61 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 207 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 567 М.
Lecture 42: KMP Algorithm || Longest Prefix Suffix
1:06:06
Coder Army
Рет қаралды 53 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 782 М.
Maximum Product Subarray - Best Intuitive Approach Discussed
20:27
take U forward
Рет қаралды 265 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН