Intersection Of Two Linked Lists: Amazon Problem | LeetCode 160 {Using Hash Set}

preview_player
Показать описание
In this episode, we solve Cracking the Coding Interview Problem Intersection Of Two Linked Lists, where we are given two linked lists that intersect at a node and we are asked to find the intersecting node. We solve this in O(A+B) linear runtime and memory using a set.

Watch and enjoy.

Top Software/ Coding Channels:

Top Python Coding Channels:

Snapchat: @christopheribe

Problem Statement:
Intersection: Given two (singly) linked lists, determine if the two lists intersect. Return the intersecting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.

Hints:
You can do this in O(A + B) time and O(1) additional space. That is, you do not need a hash table (although you could do it with one)
Observe that two intersecting linked lists will always have the same last node. Once they intersect, all the nodes after that will be the same.
Try using the difference between the lengths of the two linked lists.

Motivation Quotes:

Рекомендации по теме
welcome to shbcf.ru