If are watching this in lockdown believe me you are one of the rare specie on the earth who are willing to achieve something in life. Many students are wasting their time watching web-series, movies, playing pubg, all the best for your future. nitjstudenthere :))
@techdose4u4 жыл бұрын
Nice :)
@babbarutkarsh77704 жыл бұрын
we aren't rare there is a lot of competition
@AMITSHARMA-oh1nq4 жыл бұрын
@@babbarutkarsh7770 maybe field in which u are competing is the field which attracts most rarest minds
@mopsyched4 жыл бұрын
Watching movies isnt the end of the world nor is coding
@amar75614 жыл бұрын
bro just gave sde-II amazon test , competitiion is very high and believe me i learnt throughout this lockdown but things did not worked for me... this data structure and system design is never enough! also they will rarely ask these types of questions again ...but yes this will improve our coding skills
@Kacper-qp8kg4 ай бұрын
This explanation is brilliant, actually going into the details of why this works instead of some "fast food" problem solving the *cough* most popular leetcode youtuber serves us.
@techdose4u4 ай бұрын
Thanks for your appreciation :)
@RahulYadav-nl1ek3 жыл бұрын
i came here to understand the floyd's method however i am very impressed with they way you solved it assuming mutable Thanks mate!! Subscribed
@techdose4u3 жыл бұрын
Welcome
@shashwatbansal77762 жыл бұрын
After seeing the solution for mutable array only one sentence came to mind "You are a genius"
@AbhijeetMuneshwar Жыл бұрын
Very easy to understand the concept after watching this video.
@saikatdutta11633 жыл бұрын
As per your explanation of the problem. Solution is pretty easy, sum of all the elements - (n * (n + 1)) / 2
@techdose4u3 жыл бұрын
:)
@saikatdutta11633 жыл бұрын
@@techdose4u Am I right? or what?
@chhatrapathisivajilakkimse13713 жыл бұрын
@@saikatdutta1163 no not right , here you can have multiple repetitions of one element.. For test cases like 1 2 2 3 4 2
@fabio336ful7 ай бұрын
Easy explanation, made me understand clearly!
@mythilikarra19024 жыл бұрын
"So this solution is not at all intuitive" - I cackled
@manthankhorwal14774 жыл бұрын
I think you just complicated a point here.at 8.38 you are saying we are at index and make a node of value but when you reach 4 which has value 1 you should make node.for 1 but you jump to index 1.. ... Suppose if a number is repeating twice then there will be 2 index point to the same element So cycle entrance is always duplicate element , and harr and tortoise will work in this way only In your example 3,4,1,4,2 3->4->2->1->write here 1 will point to 4 so just point it to previous 4 in the list...
@techdose4u4 жыл бұрын
The node pointing to intersection node will always be the repeating element. I told this in the video itself.
@manthankhorwal14774 жыл бұрын
@@techdose4u But your code itself return intersecting point or entrance of cycle ...There is no logic of node pointing to the intersection... You just made repeating node twice... But yours is also good.. i am a fan of your work
@kamalsmusic4 жыл бұрын
How do you know that the collision point (where the fast and slow pointer meet) is the same distance from the duplicate element as the beggining?
@bot78452 жыл бұрын
thanks for the explanation everything is made crystal clear
@vibekdutta65394 жыл бұрын
The pigeonhole principle can also be used. Your approach is much more intuitive btw. Thanks
@techdose4u4 жыл бұрын
The question itself is based on pigeonhole principle. The Floyd cycle algo is running on pigeonhole principle.
@vibekdutta65394 жыл бұрын
Yeah I didn't know that, thanks
@techdose4u4 жыл бұрын
Welcome
@prashantsandilya61973 жыл бұрын
Wow sb upar se gaya...itni English 🙏
@techdose4u3 жыл бұрын
😅
@drashtikoladiya83133 жыл бұрын
Your content is gold✨
@techdose4u3 жыл бұрын
Thanks :)
@bhavanikasiviswanathan37074 жыл бұрын
Best video in youtube for this problem really loved it. Thank you for the video
@techdose4u4 жыл бұрын
Welcome :)
@bhavanikasiviswanathan37074 жыл бұрын
Is there any video which explains floyd detection algorithm only?
Honestly, this is one of the best video explanations for this problem. After watching multiple videos for this problem, only after the TECH DOSE explanation was I able to understand it. Thanks a ton.
@techdose4u Жыл бұрын
Welcome :)
@sureshgarine3 жыл бұрын
wow. awesome explanation. Thank you so much. keep doing the great work!
@techdose4u3 жыл бұрын
Welcome :)
@Amritanjali4 жыл бұрын
we can also solve this by taking xor of all the number in the array and the number from 1 to n so final xor value will be xor of missing number and repeated number now we can easily separate this
@techdose4u4 жыл бұрын
This will only be valid if numbers in the given array have all elements from 1 to N.
@madmax24423 жыл бұрын
Thank you so much. Took me a day to finally digest this 😅
@techdose4u3 жыл бұрын
:)
@anixanand1622 жыл бұрын
nice explanation
@imthchamp4 жыл бұрын
Thanks for the Video, really detailed, had a doubt though... 6:28, shouldn't the loop start from 1 only as 4 is already there in the LL? like 3->4->2->1-> loop to 4. OR 8:38, that LL would be 1->2->3->4->1-> loop to 2. I am guessing the second one is where a mistake was probably made.... would be great if you can clear this.
@prodiptamondal17584 жыл бұрын
i am having the same confusion for second one
@meghnasingh99414 жыл бұрын
@@prodiptamondal1758 it will go to 4 and so when 4 is pre-existing we can report it as duplicate.
@omkarrasal13952 жыл бұрын
Very nice sirrr.. Thank you so much 🙌🙏
@techdose4u2 жыл бұрын
Welcome :)
@katelynw83923 жыл бұрын
Very clear and detailed explanation, thank you
@techdose4u3 жыл бұрын
Welcome :)
@saladmaster34964 жыл бұрын
wow, what a beautiful solution
@techdose4u4 жыл бұрын
Thanks :)
@fantasy99602 жыл бұрын
great explanation!!!!thank you
@HimanshuSingh-tu7ik4 жыл бұрын
thank you for explaining through this question I was struggling on it earlier through floyd detection though it is simple .
@techdose4u4 жыл бұрын
Welcome :)
@quirkyquark992 жыл бұрын
Hey what if the first index number is repeated? Cycle won't form then.
@HimanshuSingh-tu7ik2 жыл бұрын
@@quirkyquark99 got it, thanks!
@alexsparrow86144 жыл бұрын
your teaching is very well ........... but my doubt is .... in first method(only positive integer) how to work this input = {1,2,3,100,5,100}; becz 100 is grater then array size
@techdose4u4 жыл бұрын
Please read the problem well. It's mentioned that values will be in array size range.
@anandkushwaha014 жыл бұрын
I have a doubt regarding the point III, mentioned in the algo. let's say you have an array [1,2,3,4,4]. if you represent this in link list form, it will be link 1->2->3->4 and at it will be a loop. but in cycle first node 1 is not there which is not following the point III. please correct if I misunderstood something here.
@NomadicShepherd2 жыл бұрын
So, acc. to array 1 2 3 4 4 we end up generating the self-loop at node 4 and if we follow the tortoise method to detect the starting of the loop we get 4 as result hope that helps.
@PabitraPadhy2 жыл бұрын
So, the slow and the fast are not starting from the first node, instead they start from somewhere outside. That outside is basically index 0, of the array. Think like this.. none of the nodes of the linked list points to the item before the first node. x ] -> 1->2->3->4 4 cannot point to x and make a loop, because it's not exactly a node. so, X must be outside the loop always, in out case that's index 0. None, of the array elements are 0, they cannot be that's the constraint. So, this is where you start from.
@saranyas76294 жыл бұрын
Your videos are really nice and it has made me take up leet code challenges continuously. Thank you !! Also can you provide link for Floyd cycle detection algorithm video pls???
@techdose4u4 жыл бұрын
That's in the description below. Please check it.
@sandipsubedi22944 жыл бұрын
@@techdose4u I don't see the link.
@dhruvilbhuptani7273 жыл бұрын
@@sandipsubedi2294 please wear chasma
@chetanshrivastava37624 жыл бұрын
Very nice explanation..
@techdose4u4 жыл бұрын
Thanks
@rishabhgupta98462 жыл бұрын
My code using the first method, successfully submitted int findDuplicate(vector& nums) { int i; for( i=0;i
@electric3364 жыл бұрын
9:30 The first element doesn't seem to always be in the loop. Try the list [1,2,4,2,3] .
@techdose4u4 жыл бұрын
It is never guaranteed who will be in loop. But the 1st element is never in loop.
@krystaljinluma4 жыл бұрын
@@techdose4u why did you say "the first node will always be in the cycle HAVING the repeating element" then? im confused...
@sharathvenkatesh4 жыл бұрын
What he meant was the first node is always connected to the cycle component. The first element cannot be in the cycle path since it does not have an incoming edge in the LL representation.
@HARI-ip4ep2 жыл бұрын
Searching for this comment
@HARI-ip4ep2 жыл бұрын
@@sharathvenkatesh Thank you
@mathematicalninja27563 жыл бұрын
This is pure genius/
@techdose4u3 жыл бұрын
:)
@maths_with_fun85924 жыл бұрын
Nice explanation. Thank you for this type of videos.
@techdose4u4 жыл бұрын
Welcome
@yitingg79424 жыл бұрын
What am I going to do without you Sir ?
@techdose4u4 жыл бұрын
What happened ? 😅
@yitingg79424 жыл бұрын
@@techdose4u Thank you for all the help Sir, I would not be able to survive without you!!
@techdose4u4 жыл бұрын
I will always be there. So, you do not need to worry :)
@yitingg79424 жыл бұрын
@@techdose4u Thank you so much Sir, you made me wanna cry..
@ravishankar92472 жыл бұрын
At 14:00 , why did you recreate node-4, I am sorry to say this but you have totally confused me......
@prathamsharma3502 Жыл бұрын
does using LL violates the constant space restriction ? Please explain...
@kaichenghu38264 жыл бұрын
I smash the like button then I watch the video
@techdose4u4 жыл бұрын
🤣
@omi_naik2 жыл бұрын
Hash map would also help in this case, but the problem statement says it requires constant space
@Moch117 Жыл бұрын
That’s the whole point
@shobhitkumar68204 жыл бұрын
Sir in the 7:06 part of the video i think by mistake you have made the wrong linked list i.e ypu have made 2 4's instead of showing cycle there.
@techdose4u4 жыл бұрын
I have drawn correctly. It is from value to value. Index is just used to get values.
@shobhitkumar68204 жыл бұрын
Sir but are making the repeating element two times instead of just making a cycle there only. In this way i think it will violate the fact that starting of loop is always the start pointer of cycle...plz reply sir
@shobhitkumar68204 жыл бұрын
Okay so you have not used exact cycle detection method but a slight variance of that
@techdose4u4 жыл бұрын
I have used exact same cycle detection method with just a change that we need to find the element occuring before intersection point, that is the element pointing to intersection node.
@shobhitkumar68204 жыл бұрын
@@techdose4u thanks sir👍👍
@saravanan9254 жыл бұрын
I am getting confused in this point : the 0 index element will never be in a loop. For ex: [1, 4, 3, 2, 1] I hope this forms a loop for 1st element. Correct me if I am wrong
@persianwaffle4 жыл бұрын
Hi Saravanan, the indexing starts at zero so what he meant was that since zero is not there in the array you wont get caught up in the first index forever. now you will be directed to some other index from 0th index. this means none of the index will have the index as their value. i.e. index 1 will not have 1 as value, 2 will not have 2 as a value. if it has it means that will be a duplicate element. sorry i am bad at explanation. hope it helps
@ashfaaqmir78692 жыл бұрын
@@persianwaffle not bad but terrible
@vishalBaid2 жыл бұрын
If the array have number more than the size of array like size of array let say 4 and array looks like 5,6,6,1, then this solutions(mutable array one) will not work. Correct ?
@aimanmumtaz38513 жыл бұрын
How will you create graph for a={1,3,4,2,2,5} ????
@vijayj19974 жыл бұрын
@TECH DOSE CAN you explain infamous manacher's algorithm
@techdose4u4 жыл бұрын
I will, when the time comes :)
@sriharshasamayamanthula26922 жыл бұрын
good explanation sir. But when we take input as [1,3,2,1,1] i get 3 as answer. In this case loop starts at 3. please correct me if am wrong
@ShreyaSingh-vr9qi4 жыл бұрын
Awesome explaination
@techdose4u4 жыл бұрын
Thanks
@shobhitkumar68204 жыл бұрын
In the next eg also i think you have made the wrong linked list as last node should point to 1 and not 2. Plz correct me if i am wrong
@Hhtesh3 жыл бұрын
why didn't you link 2nd 4 to the first 4 in link like you did it for 2 ? 6:55
@pulkitahuja47503 жыл бұрын
Because they are pointed to by the same indexes i.e, 4
@de-stressmusic432Ай бұрын
Beware: Assumption 4 is wrong. The video shows many lists that are not connected properly. At 12:20, 1 should be connected to a previously appearing 4 in a cycle. Instead, another 4 was created as a mistake. If you connect everything as a cycle, an element at the beginning of a cycle is the duplicate in an array(number 4 in this case) . I spent so much time figuring it out. Assumption 4 should be: The repeated number is the beginning point of the cycle.
@aryan7069_2 жыл бұрын
we can just take XOR of all elements
@yashSharma-pe1dp4 жыл бұрын
Thanks sir, your videos are gr8 as always.
@techdose4u4 жыл бұрын
Thanks
@ayushraj-zb6sv3 жыл бұрын
do interviewers expect Floyd cycle detection algo for this question ? Is't it more like just remembering the solution .. i mean its not intuitive ?
@techdose4u3 жыл бұрын
It's not intuitive, that's why I explained it thoroughly. They might expect. According to how requirements are increasing day by day, who knows. It depends on interviewer as a person. If he is logical enough then he should not expect but again, candidates are setting new standards and so they might expect.
@ayushraj-zb6sv3 жыл бұрын
@@techdose4u oh i see,anyways i understood the solution..so no worries :)
@himanshugupta76474 жыл бұрын
hi @TECH DOSE i have just started learning dsa is 8 months enough to get into amazon
@techdose4u4 жыл бұрын
Yes. But you need to give the best preparation you can for cracking it.
@random24022 жыл бұрын
Which software do you use to annotate on the screen? Please reply...
@vikramgara4 жыл бұрын
In the first solution(array mutable), the solution does not work if the number is repeated odd number of times.
@mdisi59673 жыл бұрын
We don't care about how many times the element was repeated but we want to know which one was repeated, so we stop on the first repetition of the element.
@rishabhgupta98462 жыл бұрын
int findDuplicate(vector& nums) { int i; for( i=0;i
@lomoyang30343 жыл бұрын
Where I can find the mathematic prof for the first method?
@techdose4u3 жыл бұрын
Stackoverflow
@charlesbickham66044 жыл бұрын
Could you add the numbers 1-n in the first loop and then in the second iterate through the array subtracting the values. Then you return -1*ans
10:35 I don't understand why you said "the first node will always be in the cycle HAVING the repeating element" - what does this mean? Do you mean the first node will NEVER be in the cycle? because you said it doesn't have incoming edges?
@krystaljinluma4 жыл бұрын
if we have [2,3,4,1,1], the linked list will be 2->4->1->3->1 (1points back to 3), and 2 is not anywhere in the cycle?
@punittripathi54614 жыл бұрын
A little slower explaination pace than current would be appreciated .
@techdose4u4 жыл бұрын
That would make video longer and probably I might not get good audience retention pecentage wise.
@anirudhreddybasani35554 жыл бұрын
@@techdose4u your pace is alright.
@charan7754 жыл бұрын
6:50 you are not making extra node for 2 since it is already visited. Then why did you make extra node for 4?
@aditya2345674 жыл бұрын
He has drawn correctly. It is from value to value. Index is just used to get values.
@bisatisrilatha79573 жыл бұрын
bro if we have to find element before fast==slow why return fast???????????????????????????????
@madhupatel44844 жыл бұрын
Mutable immutable??
@akhil35884 жыл бұрын
Mutable- means you can change the elements in given array.
@jatinbhatoya84204 жыл бұрын
sir aapne jo 1st trick btayi hai vo sahi nhi hai. take array as 1 2 3 4 5 1 . ur first trick is not giving correct answer for this array.
@RavisCodeDiary3 жыл бұрын
It's working, 1 -2 -3 -4 -5 -1 then at index 1 i.e. -2 which is negative. So 1 is repeating.