Day 3 - Linked Lists
Practice Questions
Intersection of Two Linked Lists

Intersection of two Linked Lists

Description

  • Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

For example, the following two linked lists begin to intersect at node c1:

Example
Example

The test cases are generated such that there are no cycles anywhere in the entire linked structure.

Note that the linked lists must retain their original structure after the function returns.

Constraints

Test Cases

  • Input:
    Output:

  • Input:
    Output:

Code

Approach 1: ``

Explanation

Analysis

  • Time Complexity: O()
  • Space Complexity: O()

Approach 2: ``

Explanation

Analysis

  • Time Complexity: O()
  • Space Complexity: O()