Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
fast === slow ??

Faraz

Feb 23, 2024

iam confused how the fast (object) will be equal to slow(object), coz in javascript two object are never same they have different memory addressess!

1,2,3,4,5,6

in this list, the fast pointer reaches the end, and the fast===slow is not being satisfied,i get it but will fast === slow will be evaluated to true ? if we are comparing two objects?

0

0

Comments
Comments
Shubham Vora
Shubham Voraa year ago

Why It Works?

  • Both slow and fast are references to nodes. When they point to the same node, they have the same memory address, so slow == fast will be true

  • In Java, comparing objects using == checks if they are the same instance, not their content. S...

On this page