Solving Arrays Questions | Find duplicates in an array | GeeksForGeeks | Nishant Chahar Ep-18
ฝัง
- เผยแพร่เมื่อ 11 ก.ค. 2022
- In this video, we'll are going to solve some more questions of the array. Arrays are really important because we are going to use them a lot in future topics.
Problem link: practice.geeksforgeeks.org/pr...
Previous lecture: • Solving Arrays Questio...
You can use my code NISHANT to get 15% Off on all GFG courses.
✨ Important Links ✨
- Don't Click Here: bit.ly/3afmPha
- Telegram Link: t.me/codeIn10byNishant
- Github Repo Link: github.com/chaharnishant11/Co...
✨ Hashtags ✨
#NishantChahar #Microsoft #DSA #Recursion #FAANG #NSIT #NSUT #engineering #internship #college
✨tags ✨
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoisation
what is tabulation
what are graphs
where to learn Operating systems
where to learn dbms
where to learn oops
where to learn computer networks
where to learn low level design
where to learn cs fundamentals
Sanchit jain
Gaurav sen
Gate smashers
Placement guide
How to start programming
where to learn cpp
where to learn python
where to learn javascript
where to learn java
Placement guide
Nishant Chahar Placement Guide
languages to learn
resources to learn data structures
Projects development
AR/VR
Blockchain Machine learning
Deep Learning
Software developer engineer ,
Side projects ,
Importance of side projects ,
Machine Learning Engineer,
How to become a machine learning engineer ,
Associate engineer
Data structures Algorithms
College Life, College, Memories
Fun Fests Chill Enjoy
IITD Mood indigo rendezvous IIT
NSUT Moksha DTU Engifest
Bits Bitsgoa
Namaste Javascript
Namaste Javascript Akshay Saini
Apna college
Apna college c++
apna college DSA
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoisation
what is tabulation
what are graphs
where to learn programming
how to start coding
where to learn coding
where to learn DSA
resources to learn programming
how to crack amazon
how to crack placement
blockchain
what is blockchain
blockchain technology
blockchain technology explained
blockchain explained
blockchain technology in hindi
web development roadmap
roadmap to learn web development
android development roadmap
MERN stack roadmap
machine learning roadmap
roadmap to learn machine learning
roadmap for deep learning
roadmap for 2nd years
roadmap for opensource
roadmap for ios development
roadmap for deep learning
roadmap to learn DSA
Day 43
Find Duplicates In An Array
Every day, you strengthen and become even more perfect. Your explanations are always accurate and simple to grasp. I appreciate all of the help you have given over the months. Your support is very helpful. Your commitment and teaching skills are outstanding. It was an excellent learning experience that I have so far greatly enjoyed. I appreciate your ongoing support from the beginning. Good luck in the future and keep up the fantastic work. I look forward to getting to know you and spending valuable time with you while learning from you. You are my inspiration and I admire you a lot. You are the best, Nishant Bhaiya!
Thank you for teaching us these approach to the type problems in such a simplified way.
Yes it's greatful to learn in simple way, you can enroll Nishant AlgoPrep DSA program for better understanding.
Great explanation ❤️❤️
what an explanation man, thank you so much
Thanku for the wonderful explanation
Learned another great algo, of topic which students usually ignores.
Thanks a lot #CodeIn10
Awesooooome explanation ❤️❤️❤️❤️
Thanks for the video bhaiya well explained......... :)
Week 7 is abt to start.
Never felt like it had came such a long way and I could follow it up everyday this long. 😂
Really consistency op😎😎😎
Thanks bhaiya 😊
Shiv
I literally got goosebumps when I see this approach. Hats off to those who come up with these ingenious ideas
And one suggestion is if possible try this problem
MAXIMUM OF ALL SUBARRAYS OF SIZE K
as the intuition behind the optimized version of this problem is also amazing and I think we all will like it
Yes it's greatful to learn you can enroll Nishant AlgoPrep DSA program for better understanding.
Your consistency says everything, great work bhaiya❤️
Nice to explanation is clear doubt from this video thank you for making this video and this type of video is need to the audience so thank you 🎉❤❤
Mast Bhai pora samaj aa gaya...❤️Hyderabad...
why are we pushing i in ans vector instead of arr[i]?
I think even if the question says that array has only one duplicate elements,you still can't use hare and tortoise method because array contains 0.
GFG ka same solution chipka diya hai😂
Gfg kya hai??
@@hanovarghese9411 It's a website for learning a lot of skills. Like programming languages, Databases, Cyber security and a lot of things.
@@hanovarghese9411 Geeks for geeks
Geeks for Geeks
Thank you very much bhaiya 💗
great content 👌
THANKS SIR 😍
Doubt:--Why are we returning index..shoudn't we return (arr[i]-2n)??
this should be the case..coz they want the elements...but you get an error if u put (arr[i]-2n)...strangely it runs if u put i...sometimes u modify ur correct ans to a wrong ans to fit a wrong question :)
Thanks 🙏🏻
Day 43 and week 7 😊 compelled ❣️
Bro in Microsoft what role u are working like web developer or app and whether u work in websites or in what
Day 43 me - programming muje smj rhi h, thanks bhaiya :)
Hello vaiya thanks for this type of videos ❤️🤞
Thank you bhaiya for the day❤💪
thanks for today
present here day 43 completed successfully best consistency bhaiya thank you Nishant bhaiya for your support ❤️ 50k soon #nishantchahar❤
Great Great Great Bhaiya 🔥🔥💓💓
But what if all numbers is different like {4,6, 28, 4, 6} is it possible?
but what if range is from 0 to N and not N-1 like in the leetcode question number 442?
Good sirji 🔥
damn knowledge 💥
💕🎉🎉50k soon
Nishant Bhaiya giveaway ka result kab aayga...eagerly waiting for Microsoft tour 💙
Please sir make more than two problems per days sir
Day 43 Completed and We will keeo going. Hopes to meet you soon bhaiya ❤️
Lacks dry run.
2nd comment now i am with u..i makeup all the previous lecture..
This method is working but this method is not ideal according to c++ standards, lets say we have array size of 5 and in that array there is an element 13, so if i calculate the index i.e index = arr[i]; // a[i] is 13
a[index] = arr[i]%n; // a[13] = 13%5;
we are accessing 13th element which is out of the range of array and it is working because of the undefined behaviour of C++, it will work for small numbers, if i try to access a large number lets say arr[4000] = 80; it will give me the segmentation fault...
This can cause a major bug in a software.
by the way you are doing great :-)
I got the same doubt..
Ig the method only works if the maximum element of the array
@@dipesh3395 because the restriction of question is the elemets range is [1,n-1 ] then only it works
Consistency is the key to success. Thanks bhaiya for such lovely content.
Thanx bhai🔥😎
Hi brother
Can you please explain the Amazon AWS deeprace event for student i am interested in it
Please make video on it on how to code the model
Please 🥺
Why are you doing redundant %n if all elements are already 0
I recommend you , Dry run krke dekho , Then you will realise
Nyc 😍☺️
My teat case did not pass its showing error of segmentation fault
but what if array has element that is greater than size of array?
Question done💥💥💥
Look at 4:42 suppose we have an array element 10 then 10%n(10%5) is 5......how do you get that 5th index in the areay
In Question it is given that if array size in 5 then element should be in range from (1-5).
Today Notes
Problem: Find Duplicates in an array
Approaches:-
1. Traverse the array and count each element.
2. Store frequency of all elements in a different array.
3. add %n for each index.
vector is a dynamic array in c++, so it automatically updates its size to accommodate its elements pusback is used to add element to the back of a vector
bhaiya solution contains error for4 1 case
Input: nums = [4,3,2,7,8,2,3,1]
Output: [2,3,4]
output should be 2,3 only
Jo questions most repeated ho companies me arrays ke wo bhi karwa digieye
public int findDuplicate(int[] nums) {
int n = nums.length;
int[] ans = new int[n];
for(int ele:nums)
{
ans[ele]+=n;
if(ans[ele]/n>=2)
{
return ele;
}
}
return -1;
}
why we are looping over the array twice ? isn't mentioned above is the precise soln?
Sir we are in 11 class please tell us about which stream is best for coding journey
Omg😮
Bro thoda speed mein krao jisse beneficial ho.
Day 43 done 🙂
Done
Day 43 done
I don't think modulo is even needed if all the value is between 1 to n-1. It would be needed if values are random but then this algo not work.
same bro
modulo is needed as we may visit the same index in future and if its value is greater than n it will give error
Same doubt here
❤❤
Please really i need help
Love Babbar bhaiya ke 450 questions bhi kara dena please 😄😄
Issue in Algo for Below INPUT , Please check below, as the expected is also wrong as 4 is not repeated and it is still giving 4 as in answer,
4 3 2 7 8 2 3 1
Your Output:
2 3 4
Expected Output:
2 3 4
I think the expected value is 2 3 and output is 2 3 8 according to this algo. Question says array of size n containing upto n-1 elements. Ur array is size 8, it should contain only upto 7 cuz 8%8=0 which is giving index 0 as well also the 4%8=4 that is adding 8 to arr[4] gives 16 that's twice the value so that's why all the value in array should be lesser than array size.
Expected output :
2,3
👍
Day 43 🔥✅
This solution will not work for non repeting array
I need help
Agar index variable use hi nhi ho raha, toh declare hi kyu kiya?
You can help me
In dry run you are creating a new array for updating the values.
But in code you are updating the index of same array.
If you update the original array then you will loss the original values.
And arr[0]%n => 2%5 = 2 not 5 but in explanation you are adding 5 LOL.
Because we get the duplicate number by the index , so it doesnt matter if we lose the original values and we find the 2%5 to find the index at which we need to modify, so that and adding 5 are two different things
I bro i need help please help me
Si biggner ke samne vector aya hi nahi hoga to vo kya samjhe bas copy to karna nahi hai chijo ko samjhna hsi na
Second today 🔥
Please help me
First here💯
Yours approach to find duplicate is not applicable to solve leetcode problem *find duplicate elements*
Please help me please 😭
Bhaiya explaination ke time pe jo music he bad me band kardo plz
poor approach. It can be done in 1 loop as well.
akhiri me galat bola hai
Apko kitna time laga tha pehli bar jab solve kiya tha tb.. Air ye apko khud ka logic hai kya?
would be helpful if you speak in english
ye ad me aditya kachve ko dekh ke gussa aajata hai
Jab array bata rahe hai ho to push pop pe Jane ki kya jarurat hai bhai sabh bigner thodi na samjhega jaldi dimple language explain karne ka na
galat explain kiya hai bhai.. pata ni kaha se 80+K subs hai tere
you doesn't taught very well by dry running more Test Cases, your explanations are not that much clear enough. your Handwriting is also poor. LoveBabbar and Raj Vikramaditya are more Better than you in every aspect.
worst explaination
You won one more member, I'm very grateful. Can you share your e-mail?
Day 43 and week 7 😊 compelled ❣️
Please help me please
Please help me please