Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8679905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:06:22+00:00 2026-06-12T21:06:22+00:00

Two Singly linked Lists, size m , r and want to insert the first

  • 0

Two Singly linked Lists, size m , r and want to insert the first linked list nodes after the head of the second linked list, and the time complexity has to be O(1) of the method.

This really an intereseting difficult problem for me. Eatch time I think of a solution, the Time complexity is O(m+r)

I need some hints to solve this. I consumed useless effort on this problem.

EDIT:

Let me share what I have so far:

  1. Create a new Linked List
  2. Add the HEAD of the 2nd list
  3. Still O(1)
  4. Add all the nodes of 1st list
  5. Becomes (n)
  6. Add the rest of the nodes from the 1st list

  7. Becomes another (n-1)

UPDATE:

What do you think about this? I got inspired directly after I asked here 🙂
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:06:25+00:00Added an answer on June 12, 2026 at 9:06 pm

    Assuming you have these structures:

    • List
      • Head node
      • Tail node
    • Node
      • Value
      • Next node

    Reminder to self: the goal is: “insert the first linked list nodes after the head of the second linked list”.

    Then all you’ve got to do is:

    // Hook up the end of list1 to the original second element of list2
    list1.tail.next = list2.head.next;
    // Set the second element of list2 to be the first element of list1
    list2.head.next = list1.head;
    

    List2 still ends where it did before (its tail node is the same).

    You’ve now got list1 with a “floating” head, which is generally bad news… but if you iterate over list1 you’ll get all the elements from both original lists…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given two unsorted single linked list of size M and N . The task
Suppose there are two singly linked lists both of which intersect at some point
How can I delete a node (between two nodes) from a single linked list
Possible Duplicate: How to reverse a singly linked list using only two pointers? This
I have an integer linked list of which both first half and second half
I am trying to implement a simple singly linked list of integers which are
I wonder if there exists some logic to reverse a singly-linked list using only
I need to merge two doubly-linked lists, but not by their values (the lists
find same node from two single linked lists. Can't use hash, Can not be
I'm implementing a singly-linked list in C and got stuck with the remove node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.