love you bhaiya chije tough he par laga rahunga aur acche se mehnat karunga aur seekhunga aap se pata ni kyo ek relatability vali feeling aati he thanks for the course love you
17:52 We can also write the statement in this way. mid = end - (end-start)/2; which looks more similar and easy to remember as mid = start + (end-start)/2
why mid=start+(end-start)/2 giving error and mid=end+(start-end)/2 not giving error?In both case mid evaluates to zero and also in both cases ig there is no overflow according to condition given in question..
@@AbhishekKumar-ks1fd if we use mid=start+(end-start)/2 then it will move to 0th index if the required element is present at index 1 .and if we use mid=end+(start-end)/2 then it will move to 1st index for which we can compare the previous element arr[mid-1] which is not the case if we use mid=end+(start-end)/2 .for better understanding dry run this case [1,9,5,3,2].
hello bhaiya. Thank you for your efforts. {17:25 bhaiya agar hum es code ka use kare tho hume mid value m koi change kare ki jarurat nhai padegi. } int s=0,e=arr.size()-1; int mid ; while(sarr[mid-1]){ s=mid+1; } else{ e=mid; } } return -1;
My intuition behind ans + K : ✅✅ We found that in the array before ans index, there are total ans elements present currently. And we know there are at least K elements missing It means that, before that ans index there should be total at least (ans + k) elements . Let's take example of the question: [2,3,4,7,11,12] , we found that before index 4th, there are total 4 elements. Now, we also know that there are at least 5 elements missing before 4th index. so at least total elements before index 4th = 4 elements + at least 5 missing elements = at least 9 elements. And we know that 9th element is basically 9 (which is missing) (NOTE: In this case total 6 elements missing before index 4, so total elements before 4 would be = 4 + 6 = 10), so 9th element is 9, 10th is 10)
ye search in rotated array ke question mai bahut din se fasa hua tha. paid course wale ka samaz hi nahi aa raha tha. lekin jab aapke video se dekha to pura logic clear ho gaya. thank you for making dsa easy
17:44 reason simple hai. If you are using comparision for arr-> mid with arr->mid-1. use mid = end + (start - end ) /2 If you are using comparision for arr-> mid with arr->mid+1. use mid = start + (end - start) /2 it depends on your way of writing code. ******* Now for the dry run part on : arr [1,6,3,2,1]. sir Used mid = start + (end - start) /2, but used the mid-1 for comparision, so for Start = 0, and end = 1. mid = 0, now if we try to compare mid with mid -1 , which was accessing the index -1. we got error.
abb mental pressure badh raha h question ki difficulty aur variation k sath kal ki claas ke quesions ko khud se debug krne m 3 ghnte extra lage taki cheeje mentally accept ho jaye 🥲
Yeh saare bohot hi simple questions hai, agar yeh bhi tumhe difficult lagg rahe hai toh tumhara basics clear nahi hai, ek baar binary search doobara se padho, different cheeze try karo code me like returning s or e in the end, etc. Ek baar binary search samajh gaye toh yeh questions bohot easy lagengi.
1:00:01 i am confuse in the else if condition ,in the previous example the value of [arr[mid] >= arr[0] ] this condition was not true so how can this code further proceed ?
Ram Ram rohit bhai abh kaafi bddiya samajh aa raha hai leetcode ke problems bhi solve kar paa raha hoon all thanx to your great effort to make us fall in love with DSA sab chamk raha hai ✅
16:19 bhaiya jb hum last pe pahuch rhe hai tb mera mid 1 ban ja rha hai isi wajah se error nahi aa rha hai start =0 , end =1 mid = end + (start-end)/2 -> 1 + (0-1)/2 -> 1 - 1/2 -> 1 isi wajah se hum arr[mid-1] wale element ko access kar pa rhe hai . bhaiya jb mai arr[mid+1] wale element ko access karne jaunga tb to error de dega na ye ???? bhaiya please reply @CoderArmy9
Q peak element class Solution { public: int peakIndexInMountainArray(vector& arr) { int n=arr.size(); int start=0,end=n-1, mid=-1,index=-1; while(startarr[mid+1]){ index=mid; end=mid-1;
Bhaiya dout support ka kya hua!?? Mene multiple times aa same chiz comment bhi ki different videos pe pr koi reply nhi aata. Mene subscription liya hua hai pr jo links aape provide kiya he bo khulte nhi or aap new link provide krbate nhi mene aase a aspect nhi kiya tha!
@Rohit bhai aap hume chamkaane mai mahnat pe lage ho humm market mai chamka denge. 🎉❤ ekdam dhaanshu ja raha h jise bolte hai dhaanshu. Bhai aapne sabb pay after placement bootcamp ke laga di hai achhe se 😂😂😂 aur jitne bhi high price unaffirdable inatituions ke laga di 😂😂😂😅😅😅😅❤❤❤. Rohit bhai coder-army family ki taraf se dil se saalam🙌🙏
class Solution { public: int findPeakElement(vector& arr) { int start=0,end=arr.size()-1,mid; while(startarr[mid-1]&&arr[mid]>arr[mid+1] ) return mid; else if(arr[mid]>arr[mid-1]) start=mid+1; else end=mid-1; } return -1; } }; // plz check anyone where is the mistake in this code i want to submit on the leetcode but it is not taking it is showint runtime error
Bhaiya I was solving a problem which I solved in O(n) time, but there was scope of improvement possible so I solved it in O(log n) time, but in Leetcode, GFG I lag in ms time and space do I need to work on improving that as well ???
int peakIndexInMountainArray(vector& arr) { int start=0,end=arr.size()-1,mid,ans=-1; while(startarr[mid-1] && arr[mid]>arr[mid+1]) { ans = mid; break; } else if(arr[mid+1]>arr[mid]) { start = mid ; } else{ end = mid ; } } return ans; I have solved this question by my self thanks Bhai ❤
okay so I've watched this one lecture for like 3-4 hours now and ab jake it has been finished now the important thing is ki aaj ke lec ka ek bhi ques khud se nahi hua; but still after you giving a simple kickstart dimaag daudne laga bhaiya thankyou for the lecture; _/\_
Q.1 another condition int arr[] = {1,2,4,7,8,9,10,11,12,13,14,15,16,17,19,17,16,15}; int n=sizeof(arr)/sizeof(arr[0]); int left = 0; int right = n - 1; int max=-1 , max_idx=-1; while (left max) { max=arr[mid]; max_idx=mid; left = mid + 1; } else { right = mid - 1; } } cout
43:06 //solved it at my own without watching the video //The code looks little complex but it beats 100% users in time complexity class Solution { public: int rightSorted(int start,int val){ if(val
Hello Coder, Sab chamak rha hai?
Hanji bhaiya
Hanji bhaiya.
mast bhaiya ab maja aa raha h. thank u bhaiya🙏🙏
Akdam bhaiya ❤❤
yeah
00:01 Find Minimum in Rotated
18:05 Peak Index
1:04:55 Kth Missing
love you bhaiya chije tough he par laga rahunga aur acche se mehnat karunga aur seekhunga aap se pata ni kyo ek relatability vali feeling aati he thanks for the course
love you
17:52 We can also write the statement in this way.
mid = end - (end-start)/2; which looks more similar and easy to remember as
mid = start + (end-start)/2
why mid=start+(end-start)/2 giving error and mid=end+(start-end)/2 not giving error?In both case mid evaluates to zero and also in both cases ig there is no overflow according to condition given in question..
@@AbhishekKumar-ks1fd if we use mid=start+(end-start)/2 then it will move to 0th index if the required element is present at index 1 .and if we use mid=end+(start-end)/2 then it will move to 1st index for which we can compare the previous element arr[mid-1] which is not the case if we use mid=end+(start-end)/2 .for better understanding
dry run this case [1,9,5,3,2].
@@adeebahmed1891 how will I get to know where to use mid=start+(end-start)/2 and where to use mid=end+(end-start)/2;
@@therealsumitshah it is a better approach. We generally use end+(start-end) /2 . We can use it everywhere.
Simple brutforce approch:
for(int i=0;i
leetcode ke 2nd test case prr fail ho jyga
what is n here?
@@collegelife7800 yeh vala try kro, fail nhi hoga,
class Solution {
public:
int findKthPositive(vector& arr, int k)
{
int i = 0, num = 0;
while(k != 0)
{
num++;
if(i < arr.size() && arr[i] == num)
{
i++;
}
else //arr[i] != num
{
k--;
}
}
return num;
}
};
0:0 q1 ,13:26 it's code,18:06 q2 39:35 it's code ,42:45 q3 1:00:34 it's code,1:04:54 q4 1:24:16 it's code and questions description se dekh lena
Thankyou
hello bhaiya. Thank you for your efforts.
{17:25 bhaiya agar hum es code ka use kare tho hume mid value m koi change kare ki jarurat nhai padegi. }
int s=0,e=arr.size()-1;
int mid ;
while(sarr[mid-1]){
s=mid+1;
} else{
e=mid;
}
}
return -1;
Bhai bhaiya ke rotated array mein dikkat aa rhi hn answer galat aa rhe hn
Superb bhaiya the way you are teaching is so unique
My intuition behind ans + K : ✅✅
We found that in the array before ans index, there are total ans elements present currently.
And we know there are at least K elements missing
It means that, before that ans index there should be total at least (ans + k) elements .
Let's take example of the question:
[2,3,4,7,11,12] , we found that before index 4th, there are total 4 elements.
Now, we also know that there are at least 5 elements missing before 4th index.
so at least total elements before index 4th = 4 elements + at least 5 missing elements = at least 9 elements.
And we know that 9th element is basically 9 (which is missing)
(NOTE: In this case total 6 elements missing before index 4, so total elements before 4 would be = 4 + 6 = 10), so 9th element is 9, 10th is 10)
19:05
class Solution {
public:
int findMin(vector& nums) {
if(nums[0]
August 5 : Revision Day 5
Questions on binary search done ✅✅✅
(BTW Last question is still little bit tough 😅😅)
ye search in rotated array ke question mai bahut din se fasa hua tha. paid course wale ka samaz hi nahi aa raha tha. lekin jab aapke video se dekha to pura logic clear ho gaya.
thank you for making dsa easy
Best explanation for search in sorted roated array easiest approach till I seen
17:44 reason simple hai.
If you are using comparision for arr-> mid with arr->mid-1.
use mid = end + (start - end ) /2
If you are using comparision for arr-> mid with arr->mid+1.
use mid = start + (end - start) /2
it depends on your way of writing code.
******* Now for the dry run part on : arr [1,6,3,2,1].
sir Used mid = start + (end - start) /2,
but used the mid-1 for comparision,
so for Start = 0, and end = 1.
mid = 0, now if we try to compare mid with mid -1 , which was accessing the index -1. we got error.
But for example , 2 3 5 4 1 0 , if we write the else if condition as arr[mid] >arr[mid+1] , then end = mid -1 ....then we get error . please check
@@shrutigawade8747it will not reach else ifpart
it will return mid as peak value i think🤔as first condition will get true..
1:35
class Solution {
public:
int peakIndexInMountainArray(vector& arr) {
int start = 0,end = arr.size()-1,mid;
while(startarr[mid-1] && arr[mid] > arr[mid+1])
return mid;
else if(mid!=arr.size()-1 && arr[mid+1]>arr[mid])
start = mid+1;
else
end = mid-1;
}
return start;
}
};
At 17:45 if array is 1 2 3 6 1 mid =4+(3-4)/2=4 for(6,1) then for last 1 we have to check for right but this time it should also give us error...so??
Funny part of video is that kth missing wala code easy category me hai (waah re leetcode) 😂 1:30:24
😂😂😂😂sahi kha use smjhne mai medium questions se jyada smay lga 😭
@@VivekSingh-hn4xr real 🥲
@@VivekSingh-hn4xrbhai dimag kharab ho gaya
abb mental pressure badh raha h question ki difficulty aur variation k sath kal ki claas ke quesions ko khud se debug krne m 3 ghnte extra lage taki cheeje mentally accept ho jaye 🥲
Same bhai😢
Yeh saare bohot hi simple questions hai, agar yeh bhi tumhe difficult lagg rahe hai toh tumhara basics clear nahi hai, ek baar binary search doobara se padho, different cheeze try karo code me like returning s or e in the end, etc.
Ek baar binary search samajh gaye toh yeh questions bohot easy lagengi.
@@tusharagarwal5306 i agree ye easy hai par ye approach ko aane ke liye practice lagega
@tusharagarwal5306 bro easy hoo ya difficult easy bolke agge niklo ge too mushkil hai question samj ne ki baad bhi ek baar khud se dryrun karo
1:00:01 i am confuse in the else if condition ,in the previous example the value of [arr[mid] >= arr[0] ] this condition was not true so how can this code further proceed ?
Day 32 done and dusted..... Crytal clear everything. Best Bhaiya.... consistency
Ram Ram rohit bhai abh kaafi bddiya samajh aa raha hai leetcode ke problems bhi solve kar paa raha hoon all thanx to your great effort to make us fall in love with DSA sab chamk raha hai ✅
40:10 and if array assigned discriminate orders then ?
class Solution:
def findKthPositive(self, arr: List[int], k: int) -> int:
start = 0
end = len(arr) - 1
while end >= start:
mid = start + (end - start) // 2
if arr[mid] - 1 - mid < k:
start = mid + 1
else:
end = mid - 1
return start + k
Literally you are a great teacher , so called overrated teachers can't teach like you brother ! ❤️
bhaiya video banana band mat karna bhut se log bhich me hi chod dete he aap please pura course complete kijiyega
thankyou
We are getting motivated by seeing your effort bhaiya..
Bhaiya agar code share kar dete to bohot accha hota, thanks for your valuable content, love you
ajka class thora hardd tha but dry run karta karta samaj aa gya bhaiya thanks ..
Haan Bhai....Kth missing wala smj aaya ?
Please like and share this series with your friends whose not offered paid course ❤
Bahut tagda lecture tha bhaiya...❤💯🚀
chalu late kiya par maza aara hai bhaiyaaaaaaaaaaa
kis year me hai bhai?
Really very nice explanation.
thanks for this type of amazing lectures.
Finally I found the best explanation for search in sorted array
Bhaiya will you cover dsa from basic to advance on UA-cam
bhaiya DSA krne ka mn ni krta tha but apki videos dhk kr mzza aa rha hai or DSA b solve ho rha hai
17:52 ka samaj nahi aaya
Whats the difference between start + (end-start)/2 and end +(start-end)/2 while calculating mid
Int overloading
@@Programmer_sumit thanks
Chamka par yeh vapis dekhna hoga best explanation k liye 👍🏻
Congratulations for 30k family members Rohit bhaai and CoderArmy family members 🎉
37:00
1:03:24 third problem
16:19 bhaiya jb hum last pe pahuch rhe hai tb mera mid 1 ban ja rha hai isi wajah se error nahi aa rha hai
start =0 , end =1
mid = end + (start-end)/2 -> 1 + (0-1)/2 -> 1 - 1/2 -> 1
isi wajah se hum arr[mid-1] wale element ko access kar pa rhe hai .
bhaiya jb mai arr[mid+1] wale element ko access karne jaunga tb to error de dega na ye ????
bhaiya please reply @CoderArmy9
hi rohit bro this videos is really help full for me thanks for this series
1:04:54 kth missing positive number
🏃♀Day 9✅
tysm bhaiya
32/180 done thanku bhaiya🙃
Q peak element
class Solution {
public:
int peakIndexInMountainArray(vector& arr) {
int n=arr.size();
int start=0,end=n-1, mid=-1,index=-1;
while(startarr[mid+1]){
index=mid;
end=mid-1;
}
else{
start=mid+1;
}
}
return index;
}
};
Bhaiya ek confusion h agar arrays ko sorted bolte h to it means ki arrays must be in increasing order 🤔🤔.
Nahi bhai, wo question mein given rhega sorted ka meaning, wo increasing ki baat kar rha hai ya decreasing ka
Bhaiya dout support ka kya hua!??
Mene multiple times aa same chiz comment bhi ki different videos pe pr koi reply nhi aata.
Mene subscription liya hua hai pr jo links aape provide kiya he bo khulte nhi or aap new link provide krbate nhi mene aase a aspect nhi kiya tha!
bhaiya i got error in kth missing element for arr=[2] and k=1
mazaa aa gaya bhaiya iss lecture se ekdam se babu wali feel ho gayi😂😂😂😂
doubt
when to use ;- while(start
It's dépend on condition
Both are same bro.
No íts not same it's dépend on condition of start ànd end
Okh.
always use while(start
Your understanding find is very best
Love you sir ❤❤
bahut bhadiya bhaiya 😀😀😀😀
this logic of rotated array for finding min. value is not working in {8,7,2,4} why ?
Pta chala bhai kyo nhi run ho rha please tell
Bhaiya last wala kth missing number thoda samajh nhi aaya
bhaya python mai to wo work nhi kar raha hai, lekin else statement mai right = mid karo to work karta hai
bhaiyaaa bht zada ache se smjh aa ra hai thank you
Day 24 Completed ✅❤🎉
Badhiya rha ye session #Chamka
apne to DSA me aag laga diya , mast he
Day 32/180 completed
Done Bhaiya... 32/180 ✅
@ rohit bhaiya 2d array kab karaoge
Watching from NIT Srinagar
ok watching from MIT
Baap of all dsa teacher rohit negi❤
@Rohit bhai aap hume chamkaane mai mahnat pe lage ho humm market mai chamka denge. 🎉❤ ekdam dhaanshu ja raha h jise bolte hai dhaanshu. Bhai aapne sabb pay after placement bootcamp ke laga di hai achhe se 😂😂😂 aur jitne bhi high price unaffirdable inatituions ke laga di 😂😂😂😅😅😅😅❤❤❤. Rohit bhai coder-army family ki taraf se dil se saalam🙌🙏
Done Bhaiya... Day 32/180 ✅
ohhh bhaisaaab
Amazing explanation bro ❤❤
peak index in mountain
class Solution {
public:
int find_pivot(vectorv){
int s=0, e=v.size()-1;
int mid = (s+e)/2;
while(s
Kth positive missing me test case fail error mar raha hai bhaiya. Aap ne submit hi nahi kiya 😢 or else you would have face same problem. Help someone.
No error n h bro
@@armywalabhai9617 Only one value in an array [2] ans suppose to be 1
Kha pr Bhai btaio mera toh run ho gya aur submit bhi
sir is like a magician
32 days completed ✅
Day 32/180, #180daysofcode #180 hard
Day-32🔥 Completed
#180daysofcode
Covering backlogs
Thank you bhaiya.
32/180 Day's full power full power ❤❤❤❤
class Solution {
public:
int findPeakElement(vector& arr) {
int start=0,end=arr.size()-1,mid;
while(startarr[mid-1]&&arr[mid]>arr[mid+1] )
return mid;
else if(arr[mid]>arr[mid-1])
start=mid+1;
else
end=mid-1;
}
return -1;
}
};
// plz check anyone where is the mistake in this code i want to submit on the leetcode but it is not taking it is showint runtime error
Return end;
Chaheye bhai
search in rotated array confusing bhiyya.but the lecture and efforts of you is good
Bhaiya I was solving a problem which I solved in O(n) time, but there was scope of improvement possible so I solved it in O(log n) time, but in Leetcode, GFG I lag in ms time and space do I need to work on improving that as well ???
Bro don't believe in that if you if you again submit your code after submitting it show different ms
Sir please coa ka lecture bhi upload kr do 😭
int peakIndexInMountainArray(vector& arr) {
int start=0,end=arr.size()-1,mid,ans=-1;
while(startarr[mid-1] && arr[mid]>arr[mid+1])
{
ans = mid;
break;
}
else if(arr[mid+1]>arr[mid])
{
start = mid ;
}
else{
end = mid ;
}
}
return ans;
I have solved this question by my self thanks Bhai ❤
Thank you so much sir🥰
Thankyou for 24 😊
Good morning 🌞🌞
okay so I've watched this one lecture for like 3-4 hours now and ab jake it has been finished
now the important thing is ki aaj ke lec ka ek bhi ques khud se nahi hua;
but still after you giving a simple kickstart dimaag daudne laga bhaiya
thankyou for the lecture; _/\_
It's comletely fine bhai, focus on making notes and do revision
@@CoderArmy9 already done bhaiya!!
@@CoderArmy9almost 9 hours lagge sabhi questions samj aagaye even samja ne ke phele kuch questions samj aagaye par last vala bhot hard tha
Rotated array min can be solved with same code of mountain problem for bottom element
Bhaiya DP k liye bhi series chahiye
Q.1 another condition
int arr[] = {1,2,4,7,8,9,10,11,12,13,14,15,16,17,19,17,16,15};
int n=sizeof(arr)/sizeof(arr[0]);
int left = 0;
int right = n - 1;
int max=-1 , max_idx=-1;
while (left max) {
max=arr[mid];
max_idx=mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
cout
test case error aa raha hai [3,1] ka
bhaiya aapka solution to pura cristal clear ho ra he but mere dwara ni aa re logics
bhaiya kya karu
Bhai as a beginner ye logic khud se aana tough hai, bas ye make sure karna is type ka question dubara choote na
Good morning bhaiya ❤️❤️
#32 out of 180
Good morning boss ❤
Good morning negi bhai❤️
vaiya Find Minimum in Rotated Sorted Array iye question thoda samjh nhi aaya !
43:06
//solved it at my own without watching the video
//The code looks little complex but it beats 100% users in time complexity
class Solution {
public:
int rightSorted(int start,int val){
if(val
Good morning Bhaiya❤
Best teacher
Good morning 🌞
Thanks for motivating bhai❤
Day 32 👍✅ Chamak Gaya