8.5 Arrays - Q's asked by Top MNC's | C++ Placement Course

  Рет қаралды 567,302

Apna College

Apna College

3 жыл бұрын

All Notes of this Lecture : drive.google.com/drive/folder...

Пікірлер: 1 700
@closer9689
@closer9689 3 жыл бұрын
Sir thoda deep explanation hona chahiye . Especially for those who are really very new to coding . Kyoki hmare liye yeh sb kuch bhot nya hai to hme yeh btaeye ki apne hr ek particular coding line Kya Soch kr code ke . Videos or zyada discriptive honi chahiye , especially while dealing with the questions. It's a humble request🙏. Guys do like if you also think so✌️.
@onkarnagarkar4693
@onkarnagarkar4693 3 жыл бұрын
I came up with a simpler solution for Q2 subarray with given sum : code is at the end if you want to jump to solution! variables: first index of the sub array to be printed is "first_idx" and last index will be "i" itself. Current sum as "sum" and input sum as "s". example array: 1 2 3 7 5 initialized= first_idx as 0 (starting index of the array) sum=0 process: using for loop, we first do the usual sum update i.e. sum=sum+a[i]; following are the possibilities: if (sum==s) means we have found the array where sum=given sum i.e. "s". cout
@onkarnagarkar4693
@onkarnagarkar4693 3 жыл бұрын
@@chhitizekumar1217 Yeah there were some corrections. I have updated the code. I could do it without while loop to keep the time complexity minimum. Have a look! void sum_s(int arr[], int n, int s) { int first_idx=0; int last_idx=0; int sum=0; int i=0; for(i=0; i
@chhitizekumar1217
@chhitizekumar1217 3 жыл бұрын
@@onkarnagarkar4693 Yeah it's good apporach. Thanks for sharing.
@blazyhell4553
@blazyhell4553 3 жыл бұрын
@039 Raunak Singh You are demotivating, go away!
@AjayYadav-um1oj
@AjayYadav-um1oj 3 жыл бұрын
// Given an unsorted array A of size N of non-negative integers, find a continuous // subarray which adds to a given number S. #include using namespace std; int main() { int n; cout n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int st = 0; int et = 0; int s; cin >> s; int sum = 0; while (st >= 0 && et < n) { if (sum == s) { cout
@waseematel8065
@waseematel8065 2 жыл бұрын
every person who is watching the videos regularly don't get panic and say explain every step of code and all because as you continue the upcoming videos you will realize that these question where very silly at this point of time coz its so basic that you wont even need to refer to anything else so just watch it and solve problems on daily basis. If you still think its getting difficult then just refer to some other youtubers or any source of website about the particular topic, clear the concept and come back to the playlist as i did during the time of functions. Do what ever it takes to grasp and understand the concept just do not give up thinking "i am not made for coding" and all that negative things ! one day all of the time you invested will give you the result. Best of luck.
@Ankit__Mishra
@Ankit__Mishra 3 жыл бұрын
Best video with worst explanation You are explaining what you are doing. You should explain why you are performing such steps.
@BackToBoi
@BackToBoi 2 жыл бұрын
Bilkul sahi bola bahi q-2 ke steps to samaj hi nhi aaye, didi ji har ek step ko aache se batate hai. Kya apko q-2 ke steps samaj aaye?
@saranshgupta9119
@saranshgupta9119 2 жыл бұрын
@@BackToBoi na bhai
@agni7274
@agni7274 2 жыл бұрын
in the third question of subaary withgiven sum , why in the first while loop we take cout
@yupp_harish3936
@yupp_harish3936 2 жыл бұрын
right
@hriteshshanty252
@hriteshshanty252 2 жыл бұрын
Sahi baat hai explaination bhht poor hai
@doraemonsharma9318
@doraemonsharma9318 3 жыл бұрын
Sir, you are a very good and pro coder. But we are at low level now. And you're teaching in a way that we are unable to understand because you are teaching in high level. Although I appreciate you're giving a really great content, yet due to your speed of teaching and also way, some of us are not able to understand. Kindly, please look into it. Will be helpful for all.
@syedafreen2642
@syedafreen2642 3 жыл бұрын
true
@pottalokesh2039
@pottalokesh2039 3 жыл бұрын
Yes bayya
@rishabhthakur2270
@rishabhthakur2270 3 жыл бұрын
True what i suggest is watch it at 0.75x speed Might help
@anuragsinghdangi985
@anuragsinghdangi985 3 жыл бұрын
True
@puneetsingh9678
@puneetsingh9678 3 жыл бұрын
accha sikhaya hai agar solution dekhne se pehle 20-25 mins khud se try kro to asani hogi smjhne me. I really like this bhaiyya's teaching as well
@067_subharajmishra8
@067_subharajmishra8 3 жыл бұрын
There is no doubt that this course is very well-designed to help the student who aspired to get into Product Based Company. But however, there is a small miscalculation that can later turn into a major flaw. This flaw is that it isn't helping the beginners as much as it should. The questions are very overwhelming and it will compel the beginners to feel demotivated and leave the course in the middle. My suggestion would be that if you could teach all the concepts and give us basic to intermediate questions to practice. After the completion of the course we will do the high-level questions such as those of MNC's etc. yours truly raj mishra
@aryanverma7800
@aryanverma7800 3 жыл бұрын
this is a crash course for final year students with less time in hand ...for basics , one can follow c++ by saurabh shukla and practice hackerrank basic problems
@manavkampani8367
@manavkampani8367 3 жыл бұрын
just a suggestion brother you shouldn't be all dependent on this course, google your doubts and do your own research when stuck. This is how one grows in this field.
@abhijitpanda524
@abhijitpanda524 2 жыл бұрын
Honesly these questions and Explainations are really good I am not a beginer , but I can understand your problems , Because you are not solving the brute force method but the more complex but Optimised method , you are feeling a bit demotivated that you can't code Try to solve the easiest Brute force method 1st then see this Optimised Solution
@sarthakkhare4600
@sarthakkhare4600 2 жыл бұрын
You are right I am not a beginner but questions are quite good but the coding explanation is like to make the pizza without adding usefull ingredients in it cheese...
@arpitakar3384
@arpitakar3384 Жыл бұрын
engineers with brain and patience can understood
@beasty773
@beasty773 3 жыл бұрын
aman sir question is clear and the dry run concept is also clear but when it comes to coding everything just goes above her heads.
@codeWithPatience
@codeWithPatience 2 жыл бұрын
Vai 1 st wala Ka code send Karna
@abhisheksaraswat663
@abhisheksaraswat663 2 жыл бұрын
@@codeWithPatience #include using namespace std; int main() { int n,i; cin>>n; int a[n]; const int N=1e6+2; int idx[N]; int Min=1e6+2; for(i=0;i>a[i]; } for(i=0;i
@codeWithPatience
@codeWithPatience 2 жыл бұрын
@@abhisheksaraswat663 Thanks vai
@priyanchauhan
@priyanchauhan 2 жыл бұрын
Merko to lagta ha ye coding baski hi nhii ha mera
@agni7274
@agni7274 2 жыл бұрын
in the third question of subaary withgiven sum , why in the first while loop we take cout
@mehboobahmed892
@mehboobahmed892 3 жыл бұрын
" questions karna to ek bahana hai Programming me sochte kaise hai ye aap ko seekhana " Thanks a lot..
@twi4458
@twi4458 2 жыл бұрын
Absolutely Agree
@saranshgupta9119
@saranshgupta9119 2 жыл бұрын
Waah waah Waah waah
@shreyaschavhan5522
@shreyaschavhan5522 3 жыл бұрын
01. First Repeating Element - [0:23] 02. Subarray with Given Sum - [7:51] 03. Smallest Positive Missing Number - [16:05]
@ritikshrivastava9442
@ritikshrivastava9442 3 жыл бұрын
har video me yahi kar
@prasadbhalerao8556
@prasadbhalerao8556 2 жыл бұрын
@@ritikshrivastava9442 Tuze kya problem he be
@sangamgorde9061
@sangamgorde9061 Жыл бұрын
Thank you bro .
@tanugiri532
@tanugiri532 Жыл бұрын
Thx 😊
@simranbansal5081
@simranbansal5081 2 жыл бұрын
Thank you apna college this dsa playlist is so good, I watched just two videos from your channel and already so many topics are clear, regarding array, subarray, and time complexity.
@rahulsaw8838
@rahulsaw8838 3 жыл бұрын
Diff. Approach for first repeating element are:o(n²),o(logn),o(n) space,o(n)without space in consideration of constraints
@ShawnFrost_7
@ShawnFrost_7 2 жыл бұрын
Here is a shorter code for the subarray sum problem having the same logic : (open in pc to view it properly) #include using namespace std; int main() { int n,st=0,end=0,sum,csum=0; cin>>n; int arr[n]; for(int i=0;i>arr[i]; } csum=arr[0]; cin>>sum; while( st
@akshatpandey8571
@akshatpandey8571 2 жыл бұрын
Is this working fine?
@ShawnFrost_7
@ShawnFrost_7 2 жыл бұрын
@@akshatpandey8571 yup the logic is same as in video and it worked perfectly on the test cases i gave it to run. ( Tell me if there are any boundary conditions that I missed, I will edit it )
@shreyanshmalviya4968
@shreyanshmalviya4968 3 жыл бұрын
My type of solution to 1st question is #include #include #include using namespace std; int main() { int n; cin>>n; int arr[n]; int idx[1000]={-1}; fill_n (idx, 1000, -1); int minidx=INT_MAX; for(int i=0 ; i>arr[i]; } for(int i=0; i=0 && idx[value]
@unknown_u_know
@unknown_u_know Жыл бұрын
❣️
@shambhavikhare9850
@shambhavikhare9850 3 жыл бұрын
Great video. Thanks for this series
@sanchitraj582
@sanchitraj582 3 жыл бұрын
Thanks Bhaiya for wonderful Explanation ❤
@abhayranjan5878
@abhayranjan5878 3 жыл бұрын
Plz conduct dout session class on each Sunday 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻 Bcz we r facing problems in few programs,nd if the dout r not being cleared we will be in more trouble❤️❤️
@abhinavagarwal2045
@abhinavagarwal2045 3 жыл бұрын
you can join my telegram group named "apna doubt" we have made to discuss the doubts
@arabindaacharya9644
@arabindaacharya9644 Жыл бұрын
For question no 1, memory consumption is very high. As we are using array of 1e6. Instead we can use a map to store traversed element
@mimadhali1157
@mimadhali1157 Ай бұрын
Thank you for the clarification. My code was not running because of this issue
@bosesj
@bosesj 2 жыл бұрын
in the last problem (and also the problem like that), instead of creating an very big array, we could just create an array of length == maximum number present in the prev array + 1 (maximum+1 cuz if length of array is equal to the max num then the array itself ll not include the max index itself), now we dont need to sort or do something else for that to find the biggest number, we could just take the maximum value (that ll be on the main array )while taking input for the main array. #edited@9thSep
@ashlex7534
@ashlex7534 2 жыл бұрын
woahh!! what a genius bhai. making that large array was very overwhelming. Thanks a bunch!
@j__x__c8823
@j__x__c8823 2 жыл бұрын
for Q1. isn't initializing -1 to an array of size 10^6, gonna take a lot of time.
@sankalpupadhyay6632
@sankalpupadhyay6632 2 жыл бұрын
No, It will only take O(N) time
@yathin8834
@yathin8834 2 жыл бұрын
initializing is liner i.e O(n)which is still less than 10^8 which is the allowed time complexity
@sumanthhegde5148
@sumanthhegde5148 2 жыл бұрын
Use Vector const int r=1e6+2; vector idx(r,-1); and you'll get a vector(dynamic array) with -1 initialized.
@santanu29
@santanu29 2 жыл бұрын
For the subarray sum problem. There is no need for extra loops. just 2 are enough. #include "bits/stdc++.h" using namespace std; int main() { int n,s; cin >> n >> s; int arr[n]; for(int i=0;i> arr[i]; int i=0,j=0, start=-1, end=-1; int sum=0; while(j s) sum -= arr[i++]; if(sum == s){ cout
@ujwalkachade7066
@ujwalkachade7066 3 жыл бұрын
9:43 two pointer algorithm work karne ke liye array sort hona jaruri hota hai na 🤔🤔 but question me strictly unsorted array bola hai
@codetogether24x7
@codetogether24x7 3 жыл бұрын
Same doubt is with me
@mohammadafnan8741
@mohammadafnan8741 3 жыл бұрын
we can do it with count sort at well na?
@parthapratik7887
@parthapratik7887 3 жыл бұрын
@@mohammadafnan8741 i think ya inclusion exlusion principle ki trh h
@parthapratik7887
@parthapratik7887 3 жыл бұрын
i think ya inclusion exclusion principle ke uper based h
@samarpratapsinghshekhawat853
@samarpratapsinghshekhawat853 2 жыл бұрын
@@mohammadafnan8741 ​ @Mohammad Afnan original array will get messed up on sorting and we would not be able to return the correct index boi
@akhilnair1649
@akhilnair1649 3 жыл бұрын
Sir,In the third problem (the one in which we had to find the smallest missing positive no) can we solve the problem with constant space rather than using bool array and also in o(n) time complexity(if so can you make a video on it).The content is superb. I havent seen any c++ course which includes problem solving anywhere in the youtube.Thanks for the playlist!
@garvitjain2669
@garvitjain2669 3 жыл бұрын
My Brain After Hearing The shayri In starting:- Waahh...wahhh...wahh....wahhh
@artirani3806
@artirani3806 3 жыл бұрын
Sahi mein yahi toh sikha rahe h bhaiya hume..Question karne k liye sochna zaroori h..literally Wahh..Wahh..Wahh
@garvitjain2669
@garvitjain2669 3 жыл бұрын
@@artirani3806 Correct!!!!!!
@HaiderAli-tb1qr
@HaiderAli-tb1qr 3 жыл бұрын
Same
@snehilsinha4689
@snehilsinha4689 3 жыл бұрын
par expectation k hisab se shayari tatti thi 😂😂. Maine socha kuch mastt hoga lol.
@sayantansinharay9161
@sayantansinharay9161 3 жыл бұрын
@Apna College can you please start the playlist of competitive programming. I think I will help others who are intermediate.
@abhijitpanda524
@abhijitpanda524 2 жыл бұрын
Honesly these questions and Explainations are really good I am not a beginer , but I can understand their problems , Because you are not solving the brute force method but the more complex but Optimised method , They are feeling a bit demotivated that they can't code
@dhruvpandey6502
@dhruvpandey6502 2 жыл бұрын
100 percent true i am leaving the course in the middle because it is way too advance approach can u recommend me other cannel from where i can learn dsa
@anuragvermav6008
@anuragvermav6008 Жыл бұрын
Q1 0:23 first repeating element Q2 7:50 subarray with given sum Q3 16:05 smallest positive missing number
@proteanguy3411
@proteanguy3411 3 жыл бұрын
Ye video badhia thi pehle se 😁 first question ki confusion ko chod ke 👍
@pranavgyara7140
@pranavgyara7140 2 жыл бұрын
22:48 I think in last for loop it must be iterating till i
@deepaksai3637
@deepaksai3637 2 жыл бұрын
Hi sir,i am very thankful for your course but your level of explanation is enough for coders who are able to crack product based companies .Naming the course as beginners to advanced pls explain in detail or expose the people more to lower order questions before these.I stopped 5 times this course and came back again and again to learn something.
@sanchitraj582
@sanchitraj582 3 жыл бұрын
Your content are great . Evergreen 💚
@arka6302
@arka6302 3 жыл бұрын
I have a doubt in the second question(subarray wala). In line 33 we declared a nested while loop so how complexity is O(n) is now O(n^2) Please explain
@AbhayGupta-kd9rm
@AbhayGupta-kd9rm 3 жыл бұрын
Yes bro same question!!!
@rajchaulagain6603
@rajchaulagain6603 3 жыл бұрын
The complexity is still O(n). Check once again!! the inside loop is implemented on Sum not on n. Hence O(n) time complexity.
@mjustboring
@mjustboring 3 жыл бұрын
let's see sum example: int count = 0; for(int i=0; i
@AbhayGupta-kd9rm
@AbhayGupta-kd9rm 3 жыл бұрын
@@mjustboring♥️😘
@yashshelar8605
@yashshelar8605 2 жыл бұрын
@@rajchaulagain6603 thx
@HimanshuSingh-tu7ik
@HimanshuSingh-tu7ik 3 жыл бұрын
bhaiya ne improve kiya hai sahi mein hats off for his efforts
@subhammishra316
@subhammishra316 2 жыл бұрын
guys in last question we can do like this int one=0; for(int i=0;i
@anchitsri
@anchitsri 3 жыл бұрын
Thanks sir for such a nice representation of these questions. You have cleared all my doubt in these questions and also build a new strategy for thinking these type of question.
@madhusudananand9059
@madhusudananand9059 3 жыл бұрын
Urvi didi k lectures jayada ache se samajh aate hai please urvi didi se hi continue karwao
@krishnasingh1261
@krishnasingh1261 3 жыл бұрын
Ha yaar isko bhejo wapas
@krishnasingh1261
@krishnasingh1261 3 жыл бұрын
Mam ko hi bulao
@KundanKumar-uj2in
@KundanKumar-uj2in 3 жыл бұрын
@@krishnasingh1261 bhai ye pura team h jo work karte hain aapke liye kuch topic ye bhi karwate h kuch mam v so isliye concept samjhne ki kosis kro teacher does not matter how passonate u r thats matter
@krishnasingh1261
@krishnasingh1261 3 жыл бұрын
@@KundanKumar-uj2in exactly, we r passionate and thts y we want to understand it but we arent able to
@puneetsingh9678
@puneetsingh9678 3 жыл бұрын
@@krishnasingh1261 accha sikhaya hai agar solution dekhne se pehle 20-25 mins khud se try kro to asani hogi smjhne me. I really like this bhaiyya's teaching as well age ab topics hard hongi agr ye follow nhi kiya to koi bhi sikhae retain nhi kar paoge just a suggestion
@polymorphs
@polymorphs 3 жыл бұрын
This particular video of the playlist became the shows stopper...................moved one
@ASMR-bu8qc
@ASMR-bu8qc Жыл бұрын
I just love the approach that you used in the last question
@thebeats5234
@thebeats5234 2 жыл бұрын
Why we have made N integer as const?? is it possible to implement code without making it as constant?? And cant we use N=1e6 only instead of using 1e6+2???
@Ocean_77848
@Ocean_77848 Жыл бұрын
for 2nd problem you may try #include using namespace std; int main() { int a[10]={5,6,4,8,9,3,25,4,10,7}; int i,j,sum; j=0; sum=0; for(i=0;i
@CruelCreations
@CruelCreations 11 ай бұрын
O(n^2) complexity
@gensonic
@gensonic 7 ай бұрын
😂🎉😮😮😂😮😅😅❤😂😮😊
@AshishKumar-ny4cq
@AshishKumar-ny4cq 2 жыл бұрын
two pointer logic ko normally itne aasan logic to complicate kar diya if(sums) i++; Par rest aacha tha got to learn new things thanks...
@parthapratimghose173
@parthapratimghose173 3 жыл бұрын
did one with o(n) will share the solution soon what you have done is crossing on^2 in one loop which can cause error ! my main loop is start=0,end=1;final1=start,final2=end while(start
@devanshgupta5281
@devanshgupta5281 3 жыл бұрын
Bhayia loving this content. A request please also make videos on main subjects also(dbms,cao...).
@483_saurabhjindal6
@483_saurabhjindal6 3 жыл бұрын
study cao from bharat acharaya
@483_saurabhjindal6
@483_saurabhjindal6 3 жыл бұрын
study cao from bharat acharaya
@jubinben4538
@jubinben4538 2 жыл бұрын
According to the logic for the last question, if no smallest +ve element is missing from the array the answer won't be -1, it will be largest element in array "a "+ 1.
@vishaljha5071
@vishaljha5071 2 жыл бұрын
how?
@abinvarkey2331
@abinvarkey2331 2 жыл бұрын
yeah i thought about that too, and according to his code, the ans will not be -1 because the check is if(check[i]==false) ans=i; so if array has all positive numbers till the end of a[ ] then next check[i] will give false for number not in a[ ] (here i is beyond a[ ] limit)
@harshithp3007
@harshithp3007 3 жыл бұрын
for(int i=0;i=2){ cout
@yagamilight08
@yagamilight08 2 жыл бұрын
sir in the second for loop if no such num is found till 'n' length then it will automatically give the element which will be one more than the max of the array because loop is running till N...perhaps it should be n instead.(in last problem)
@shreyansh2729
@shreyansh2729 2 жыл бұрын
my approach for 2nd ques. (subarray with given sum): int main(){ int n,s; cin>>n>>s; int arr[n+1]; arr[n] = 0; for(int i=0; i>arr[i]; } //main logic (optimised approach) int j=0; int sum =0; for(int i=0; i
@MyCodingCollege
@MyCodingCollege Жыл бұрын
//Q.1 Frequency of an element in an array, Consider the repeated element which comes first. #include using namespace std; int main() { int n; coutn; int arr[n]; cout
@alonegaming3424
@alonegaming3424 Жыл бұрын
@shahab bro mera 1 question wala code run he nhi ho raha h vo khali input le raha h arr[n] ke liye aur end ho ja raha h
@IrfanAli-so5hh
@IrfanAli-so5hh Жыл бұрын
Can u please tell me what is this "1e6"?
@akshaykshetrapal8372
@akshaykshetrapal8372 11 ай бұрын
@@alonegaming3424 ha sahi bola nahi run hora
@ayushpratapsingh2540
@ayushpratapsingh2540 3 жыл бұрын
The last question has been made very complex to understand. I have a shorter and simple approach to it. First sort the array in ascending order and then write this code: j=1; for(i=0;i
@shrutigupta9319
@shrutigupta9319 3 жыл бұрын
Awesome Series!!
@kerinpithawala324
@kerinpithawala324 3 жыл бұрын
Another approach for small positive missing number: 1) Sort the array. 2) start a while loop for i=0 till n: a. if condition array[i]>-=0 if the difference between the present array element and its next element is not equal to 1 then return array element+1
@raniwalafabrics5468
@raniwalafabrics5468 3 жыл бұрын
TLE error aegya
@harshdeeppandey8902
@harshdeeppandey8902 2 жыл бұрын
your approach is right but complexities are the main boss in algos
@shubhamp_web
@shubhamp_web 2 жыл бұрын
@@harshdeeppandey8902 right
@DivyanshuKashyap-op3mp
@DivyanshuKashyap-op3mp Жыл бұрын
that will only work if the elements are arranged in order
@onkarnagarkar4693
@onkarnagarkar4693 3 жыл бұрын
I came up with a simpler solution for Q2 subarray with given sum : code is at the end if you want to jump to solution! variables: first index of the sub array to be printed is "first_idx" and last index will be "i" itself. Current sum as "sum" and input sum as "s". example array: 1 2 3 7 5 initialized= first_idx as 0 (starting index of the array) sum=0 process: using for loop, we first do the usual sum update i.e. sum=sum+a[i]; following are the possibilities: if (sum==s) means we have found the array where sum=given sum i.e. "s". cout
@mansha6566
@mansha6566 3 жыл бұрын
same I did
@shivambajpeyi9008
@shivambajpeyi9008 3 жыл бұрын
Thanks bro
@shivambajpeyi9008
@shivambajpeyi9008 3 жыл бұрын
I agree it's working fine for s=12, but for s=15 it's not working, plz help...
@shivambajpeyi9008
@shivambajpeyi9008 3 жыл бұрын
@@mansha6566 I agree it's working fine for s=12, but when I tried for s=15 it's not working, plz help...
@mansha6566
@mansha6566 3 жыл бұрын
@@shivambajpeyi9008 I DID IN THIS WAY : while(j-i
@ShubhamKumar-rt4jy
@ShubhamKumar-rt4jy 3 жыл бұрын
In third program when we do i=0 istead of i=1 in last loop its show error. Can i know why this is so.
@aryanshmalviya1067
@aryanshmalviya1067 3 жыл бұрын
Isse accha doubt solving abhi tak toh kisi ne nahi kiya , thanks bhaiya!!!!!!!!!
@prathamshah5929
@prathamshah5929 3 жыл бұрын
Sir but in 2 pointer approach the array must be sorted?
@ritikshrivastava9442
@ritikshrivastava9442 3 жыл бұрын
14:32 you used two while loops so time complexity is O(n square) then what is the significance of using this logic we can also done in by using two for loops and time complexity is also O(n square)
@prathamgwari9027
@prathamgwari9027 3 жыл бұрын
I am also stuck here. Someone please explain.
@unigtechy4130
@unigtechy4130 3 жыл бұрын
​@@prathamgwari9027 at the second """"while""" just replace with """if""" ||your code just works fine and the time complexity will be O(n)
@unigtechy4130
@unigtechy4130 3 жыл бұрын
at the second """while""""" just replace with """""""""""if""""""|||| your code just work fine and the time complexity will be O(n)
@hmswrth
@hmswrth 3 жыл бұрын
even with 2 loops here, you'd only get O(2n) in the worst case which is O(n). Dry run the test case against the code. Run it against a=[35,1,31], s=32 to understand it better.
@pankajvishwakarma3124
@pankajvishwakarma3124 3 жыл бұрын
@@hmswrth first you check for a[ ]={2, 3, 4, 9, 5, 4, 1}, s=10 . it will come O(n square) which is in worst case scenario. but in brut force approach it will always O(n square) in all three cases , therefor this approach is optimal.
@computersciencelover3177
@computersciencelover3177 2 жыл бұрын
Thank you and God bless you sir 🙏
@akshatthakur5967
@akshatthakur5967 3 жыл бұрын
Is it that if required time complexity is of order n then we avoid nesting of loops but we can code seperate loops?
@amardsalujasingh4094
@amardsalujasingh4094 3 жыл бұрын
App best hoooo or Yeah Fact hai Fact hai Fact hai 😂
@artirani3806
@artirani3806 3 жыл бұрын
@amardsaluja singh Bikul sahi kaha😇🤟🤟
@akhilsukhnani2659
@akhilsukhnani2659 3 жыл бұрын
A better approach that can save space complexity as well, in the first question (finding the minimum index of repeating element is):- #include using namespace std; int main() { int n; int maximum=-1; cin>>n; int arr[n]; for (int i = 0; i < n; i++) //Taking array input { cin>>arr[i]; maximum = max(arr[i],maximum); } int minm_index = n; int arr1[maximum+1] = {0}; for (int i = n-1; i >= 0; i--) { if (arr1[arr[i]]==1) { minm_index = min(i, minm_index); } else { arr1[arr[i]]++; } } cout
@pranshu_awasthi
@pranshu_awasthi 2 жыл бұрын
You're clearly using another array arr1 , how does that save space ?
@devanshkushwah6335
@devanshkushwah6335 2 жыл бұрын
bro no you are not saving the space as you are doing operation inside the input section, u are not allowed to do so
@anantsaxena7876
@anantsaxena7876 2 жыл бұрын
your code will produce output if someone gives a value more than 10^6 whereas it should display error for exceeding the limit
@vrandakansal5940
@vrandakansal5940 3 жыл бұрын
Approch on both questions is amazing...mene socha hi ni tha aaisa bhi ho skta h..😁 Thanks a lot...bhaiya
@yashvisoni5819
@yashvisoni5819 3 жыл бұрын
sir bohot hi acchi video thi or bohot hi simple way me solve Kiya bcz mene bohot sari website se problem ko Dekha but ye bohot hi simple way me solve karvaya hai so thank you, sir
@ankitkumarpathak6768
@ankitkumarpathak6768 3 жыл бұрын
what about when 2 or more sub array having same sum ??
@parvshah6417
@parvshah6417 3 жыл бұрын
//return the smallest index of the repeating element(problem 1) #include #include using namespace std; int main() { int n=0,i; coutn; cout
@it026sanjanadaki2
@it026sanjanadaki2 2 жыл бұрын
Hey when I saw the problem I first thought of nested for loop outer loop starting from 1 to n-1 inner loop from 0 to i and applied condition if arr[I]==arr[j] I stored value of j in my count variable thn applied min function It's right to think either way??
@yogeshjangra2822
@yogeshjangra2822 2 жыл бұрын
@@it026sanjanadaki2 yes
@ayushkumar6575
@ayushkumar6575 Жыл бұрын
bro 1st wale ka answer to hames 1 na aayega kuyki 5 ka index 1 hai na to ye bhaiya video me 2 q bol rahen??
@b_14_charvykoshta52
@b_14_charvykoshta52 3 жыл бұрын
phenomenal !
@aayushraj4733
@aayushraj4733 3 жыл бұрын
Bhaiya aap asse pdha rhe jaise hm sb ko bht Kuch aata ho
@shayankabasi160
@shayankabasi160 3 жыл бұрын
A true exceptional course in the whole internet - waiting for whole series to upload
@RadixYT
@RadixYT 2 жыл бұрын
10 baar try kr lia 1st problem ka he solution smj nhi rha wasted like over 4 hour
@ajaykumartyagi5105
@ajaykumartyagi5105 2 жыл бұрын
Same with me the problem is with tutor not us These are the tough programs but not that much ,after 2-3 times we all will get it.
@karthikbs9765
@karthikbs9765 2 жыл бұрын
bro he also initialised wrongly it must be int_max not -1; if we need min while initiating with -1 is literally wrong
@anandkumarsingh1404
@anandkumarsingh1404 2 жыл бұрын
ye probleam ko itna long kyu la gaye h pata nahi simple ma vi to ban sakta h na
@priyajha944
@priyajha944 2 жыл бұрын
@@anandkumarsingh1404 @Anand Kumar Singh Simple (Brute force) method se bhi ban jaaega problem but its time complexity would be O(n²) which will exceed compilation time limit for larger size of n. That's why to make the program more efficient (to reduce the time complexity of the program to O(n)) we have used this approach.
@user-tm5pw6qe8j
@user-tm5pw6qe8j Жыл бұрын
another method to do last question- #include #include #include using namespace std; int32_t main() { int n; cin>>n; int a[n]; for(int i=0;i>a[i]; } int mn = INT_MAX; for(int i=0;i0) { mn = min(mn,a[i]); } } cout
@shreyanshmalviya4968
@shreyanshmalviya4968 3 жыл бұрын
instead of using for loop and increase time ,you can just use fill_n (idx, 1000, -1); function to declare all the elements of the array as -1.
@deepakparwani6343
@deepakparwani6343 3 жыл бұрын
memset se bhi ho jyga bhai
@shreyanshmalviya4968
@shreyanshmalviya4968 3 жыл бұрын
@@deepakparwani6343 Yes there are tons of ways to do that.
@Dr.Funknstein
@Dr.Funknstein 3 жыл бұрын
Dude the way you speak is awesome, I've never had this much fun solving questions. oh and initializing N as 1e6+2 yields some error that's not prompted at runtime, I just get thrown out of the program as soon as it runs but I could fix that by changing it to 1e5. What could that be about?
@ProductionReadyApp
@ProductionReadyApp 3 жыл бұрын
Same problem happening with me in vs code.
@mukulgupta8329
@mukulgupta8329 3 жыл бұрын
Yes same here and its only happening in VS Code Windows
@mukulgupta8329
@mukulgupta8329 3 жыл бұрын
@@sayandutta9506 K thanks But it didn't happen anywhere else so I am wondering why only in VS Code
@mukulgupta8329
@mukulgupta8329 3 жыл бұрын
@@sayandutta9506 I tried your way but its still not working in my program. I found another way that is find the max number in the array using a loop and then make it the length of the index array. It won't change the time complexity but reduce unnecessary storage for small inputs. PS first increase it by 2 but still the memory maxes out when I input a number bigger than 519064
@Mrugal7
@Mrugal7 3 жыл бұрын
Thanks For This , i have been facing this difficulty since 4-5 Hrs
@pranchalkushwaha7407
@pranchalkushwaha7407 3 жыл бұрын
ek video ko achhi tarah se samaj kar code karne me maximum 1 se 2 din ja rha hai ... kya itna time sahi hai.....
@murarichaudhary5602
@murarichaudhary5602 Жыл бұрын
Sum array with given Sum-->> we can do this in n time by this approach #include using namespace std; int main() { int n, S; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } cin >> S; int st = 0; int en = n; int nowt = 0; string calc = ""; int CrrSum = 0; int ct = 0; while (st < en) { CrrSum = CrrSum + arr[st]; if (CrrSum > S) { //we are re initilize perimeters ct++; st = ct; nowt = st; calc = ""; calc += to_string(nowt+1); CrrSum = 0; continue; //we are continur here beacause st will further increase at bottom } else if (CrrSum == S) { calc += " "; calc += to_string(st+1); break; } st++; } cout
@MahipalSingh-tc8fm
@MahipalSingh-tc8fm 2 жыл бұрын
the 1st que can be done with almost 0 time complexity and very less space complexity(Even u can save the time for taking input in array) here's my approach : #include using namespace std ; int main(){ int n,k ; cin>>n; unordered_sets; int i =0; for(i;i>k; if(s.find(k) != s.end()){ cout
@ronakbothra6371
@ronakbothra6371 3 жыл бұрын
i think there is some error at 19:18 on check[1] and check[2] , t and f are misplaced there :)
@g8dboyplays790
@g8dboyplays790 3 жыл бұрын
yes i noticed that too
@lifeoeshita
@lifeoeshita 3 жыл бұрын
I think not, because here we also placed true and false like a[i] = i, mean a[2] = 1 that's why index 1 should true. Check the last code.
@nitishverma1484
@nitishverma1484 3 жыл бұрын
It's not correct and when you change the input in array it will not work
@lifeoeshita
@lifeoeshita 3 жыл бұрын
@@nitishverma1484 2. By iterating over the array and marking non-negative a[i] as true i.e. if(a[i] >= 0) check[a[i]] = True just check this step 2 on the given material
@shivamthakur7324
@shivamthakur7324 3 жыл бұрын
@@lifeoeshita as per the explanation given in viDeo , itreat over the array and mark non negative as true , so at I=5 after all the iteration of array 0,-9,1,3,-4,5 .check array should look like T,F,T,T,F,T so by that we will getting index 1 as smallest missing no.
@devanshkushwah6335
@devanshkushwah6335 2 жыл бұрын
time complexity in 1st questions is exceeding according to the constraints
@pranayjain._
@pranayjain._ Жыл бұрын
A very simple code for Q.2. int main() { int n=5,s=12, minid= -1 , maxid = -1; int a[5]={1,2,3,7,5}; for(int i=0;i
@rahulgoel8572
@rahulgoel8572 3 жыл бұрын
what is the use of while (js) and all that
@rahulgoel8572
@rahulgoel8572 3 жыл бұрын
in question subarray with given sum s
@rajarshimondal8247
@rajarshimondal8247 2 жыл бұрын
For the 2nd Problem.... I want to ask two things..... 1) Here nested while loop is used and that might make the code of O(n²) order.... Please explain it. 2) Is the part before 2nd while loop needed? (I mean till the end of 1st while loop)..... Cause the part after that is running fine and gives answer in all cases...... And I think that 1st while loop is a special case of 2nd bigger while loop only...... So is it needed?? Please reply 🙏🙏🙏🙏
@meme_eternity
@meme_eternity Жыл бұрын
1) It will not make them O(n²) order u just dry run on any example made by ur self and u will be able to get how and why i am saying this. 2) Not able to understand your doubt
@ChillVibes_47
@ChillVibes_47 3 жыл бұрын
लाइव क्लास आने का तो बहाना है ।। हमे तो अपना कॉलेज पे जाना है ।।।
@AmanSingh-oc5tu
@AmanSingh-oc5tu 3 жыл бұрын
bhaiya no word this all c++ course dil sai love uhh and thnk yu so much
@niteshguleria9901
@niteshguleria9901 3 жыл бұрын
In 4:25 I have a little better version . Instead of line 16 bcs it will create an array with huge size y not give : for (int i = 0; i < n; i++) { cin>>array[i]; maxElement=max(array[i],maxElement); } while taking input we will get to know the maximum element and then make array (line 17) int newArray[maxElement+1]; the size will be according to max element. That will optimize it a little more.
@garvitsingh2593
@garvitsingh2593 3 жыл бұрын
this series is helping so many of students that even comments in comment's section cant explain its importance .. thank you sir for guiding us and helping us!!
@rutvikrana512
@rutvikrana512 3 жыл бұрын
Approach Of The First Question Can Be Optimized. #include using namespace std; int main(){ int arr[] = {3,4,5,6,7,8,9,6,7,9}; int n = sizeof(arr)/sizeof(arr[0]); int temp[1000] = {0}; int index = n; for(int i=n-1;i>=0;i--){ if(temp[arr[i]]==1){ index = min(index,i); } else{ temp[arr[i]]++; } } std::cout
@37omgumgaonkar28
@37omgumgaonkar28 3 жыл бұрын
Bhaiya I have a problem while running 1st problem the code gets run automatically without taking input I shared you file pls check it out drive.google.com/file/d/14tDq_lcSKDZU27xTo9uCo060J3LmIebO/view?usp=drivesdk
@shreyanshmalviya4968
@shreyanshmalviya4968 3 жыл бұрын
@@37omgumgaonkar28 Hey there I am Shreyansh Malviya . I am 15 years old. I have fixed you code. the main causes it was not working were:- 1. for INT_MIN the library needed is so I added it. 2. you forgot to add library needed for cout and cin. *don't worry about the libraries you can add the #include "bits/stdc++" to add all the all necessary libraries in the video also he added the same library 3. on line no. 26 you wrote 1e6+2 but i replace it with 1e5+2 I also don't know why it didn't worked with 1e6+2 4. There were 2-3 bracket errors; because of misplacing brackets the link to the correct answer is docs.google.com/document/d/1bd44R_ycM8tMEzjxoYQJ5BwvH_bhh4maA4bqFTbQlag/edit?usp=sharing Glad to help you :-D
@harshchoudhary_5774
@harshchoudhary_5774 2 жыл бұрын
@@shreyanshmalviya4968 thanks bhaiya i have same problem 6 months ago😊.
@vaibhavsharma8465
@vaibhavsharma8465 3 жыл бұрын
Bhaiya mja aagya in questions ko krke... Aapne bhot accha smjhaya h.... Ekdum dhaansu😃😃
@muhammadshoaib189
@muhammadshoaib189 3 жыл бұрын
Bhayia G !! Sub Array Sum Wale Problem ki time complexity for worse case Kia baan rahi hai!! I think it's n2 (square) .. Koi Aur hi help kardo
@total_5300
@total_5300 3 жыл бұрын
sir i want to say that please mentain your speed bcs i did not understand how is working our code thanking you
@akshatvyas2594
@akshatvyas2594 3 жыл бұрын
In question "Subarray with given sum" 4 5 would *also* be an answer .
@pritishpattnaik4674
@pritishpattnaik4674 3 жыл бұрын
same bro
@pritishpattnaik4674
@pritishpattnaik4674 3 жыл бұрын
u have missed the break statement after updating st with i+1 and en with j+1
@akshatvyas2594
@akshatvyas2594 3 жыл бұрын
@@pritishpattnaik4674 right 👍
@the3idiots787
@the3idiots787 3 жыл бұрын
do anyone try this code on gfg .its not passing all the test case . is it happening with me only
@hrithikgupta9469
@hrithikgupta9469 3 жыл бұрын
Sir please tell me how you think suitable time complexity of the this program using constrains.
@mbillah0-teched
@mbillah0-teched 2 жыл бұрын
Find a continuous subarray which adds to a given number S. If there are multiple such subarrays which one should we consider? Like in 1 2 3 7 5 array: Two subarray (2 3 7=12 and 7 5=12) has the sum=S. For those ans are [2,4] and [4,5]. Which one will be considered as right ans?
@accepted5856
@accepted5856 3 жыл бұрын
Please show how can we further optimize the question 'First Missing Positive Integer' in O(1) space
@gauravjaiswal7407
@gauravjaiswal7407 3 жыл бұрын
is some of the questions, explanations were not clear !!!!!!!!!
@piushpaul4880
@piushpaul4880 3 жыл бұрын
Watch it in slow speed....don't expect yourself to understand it in once .
@rajveerrathod1182
@rajveerrathod1182 3 жыл бұрын
explanation is far better then anyother course plz do cooperate and do nt make comment like this
@swarnamitra2542
@swarnamitra2542 3 жыл бұрын
Thanx a lot . great teaching but one request can u make some more videos on the programms asked by these MNCS during interview plzzz😊😊😊
@prajapatishyamdineshkumar4456
@prajapatishyamdineshkumar4456 2 жыл бұрын
I think this one is easier for last qs. #include using namespace std; int main(){ int n; cin>>n; int arr[n]; for(int i=0;i>arr[i]; }int min=0,j=0; int flag=0; while(j=5){ cout
@MohdIrshad-kt7ft
@MohdIrshad-kt7ft 3 жыл бұрын
Waise mai isi saal DTU me admission lene wala hu lekin phir bhi mujhe coding me interest ki wajah se mai ye dekh raha hu. Nice aman bhaiyya
@aritradhabal
@aritradhabal 3 жыл бұрын
Konsa branch bhaiya?
@HelloRana
@HelloRana 3 жыл бұрын
same bro i am also joining nsut may go to dtu in next round
@MohdIrshad-kt7ft
@MohdIrshad-kt7ft 3 жыл бұрын
@@aritradhabal yrr mai outside delhi ka hu mujhe electrical hi mil sakti hai
@MohdIrshad-kt7ft
@MohdIrshad-kt7ft 3 жыл бұрын
@@HelloRana aap delhi ke ho ya outside
@HelloRana
@HelloRana 3 жыл бұрын
@@MohdIrshad-kt7ft delhi
@ravichavda1576
@ravichavda1576 3 жыл бұрын
In Vs code terminal when we intialize N=1e6 or 1e5. It terminates with exit code 1
@nikhiljha3168
@nikhiljha3168 3 жыл бұрын
same problem
@pandeyshashidhar
@pandeyshashidhar 3 жыл бұрын
int idx[N]; I think in this You have taken n . mine code is running #include #include using namespace std; int main() { int n,mx=-1,j=0 , ans=0; cin>>n; int a[n]; for(int i=0;i>a[i]; } int N = 1e6; int idx[N]; for(int i=0;i
@soumojitchowdhury151
@soumojitchowdhury151 2 жыл бұрын
Yes in vscode it doesn't executer after 1e6 part
@shrutibansal-5262
@shrutibansal-5262 3 жыл бұрын
And thanku so much bhiya to teach us... Hats off Aman bhiya and his team..
@theyoutuber778
@theyoutuber778 Жыл бұрын
In the first question, the index value from the first array becomes the element in the second array. And the elements in the first array are the index values in the second array.
@alokmishra6571
@alokmishra6571 3 жыл бұрын
in the first repeating array question what if we have an element as a negative number
@bosesj
@bosesj 2 жыл бұрын
there ll not be in this case, see the constraints
@varunsingh9999
@varunsingh9999 2 жыл бұрын
index wale array me INT_MIN se intialise krna pdega shyd ( for loop ke andr )
@frekinshorts4237
@frekinshorts4237 3 жыл бұрын
Where did min(mindind , idx[a[i]]); Please explain the use of this function 🙏
@mehboobahmed892
@mehboobahmed892 3 жыл бұрын
It is like 2 = Min(2,6) Here min is function in c++ which returns smaller value between..(2,6)
@Explore_with_anish
@Explore_with_anish 3 жыл бұрын
it will compare the index of repeating number and update minindx.
@keshavbajaj3055
@keshavbajaj3055 3 жыл бұрын
tActually this below code was sufficient for sum of subarray problem while(js) { sum -=arr[i]; i++; } if(sum==s) { start=i+1; end=j+1; break; } j++; }
@piyushmusaddi1272
@piyushmusaddi1272 3 жыл бұрын
Thank you so much sir, never thoughts of any of such approach while solving codes
8.4 Array Challenges | C++ Placement Course
39:41
Apna College
Рет қаралды 787 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 60 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 6 МЛН
Super gymnastics 😍🫣
00:15
Lexa_Merin
Рет қаралды 89 МЛН
Кәріс өшін алды...| Synyptas 3 | 10 серия
24:51
kak budto
Рет қаралды 1,3 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 599 М.
11. Pointers in C++ | Guaranteed Placement Course
19:03
Apna College
Рет қаралды 615 М.
I solved 541 Leetcode problems. But you need only 150.
7:42
Sahil & Sarra
Рет қаралды 2,2 МЛН
9.1 Two Dimensional Arrays | 2D Arrays | C++ Placement Course
21:24
Apna College
Рет қаралды 530 М.
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,2 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 60 МЛН