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

  • SEARCH
  • Home
  • 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 401525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:02:31+00:00 2026-05-12T17:02:31+00:00

This question may be old, but I couldn’t think of an answer. Say, there

  • 0

This question may be old, but I couldn’t think of an answer.

Say, there are two lists of different lengths, merging at a point; how do we know where the merging point is?

Conditions:

  1. We don’t know the length
  2. We should parse each list only once.

Example of two merged linked lists.

  • 1 1 Answer
  • 1 View
  • 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-05-12T17:02:31+00:00Added an answer on May 12, 2026 at 5:02 pm

    If

    • by “modification is not allowed” it was meant “you may change but in the end they should be restored”, and
    • we could iterate the lists exactly twice

    the following algorithm would be the solution.

    First, the numbers. Assume the first list is of length a+c and the second one is of length b+c, where c is the length of their common “tail” (after the mergepoint). Let’s denote them as follows:

    x = a+c
    y = b+c
    

    Since we don’t know the length, we will calculate x and y without additional iterations; you’ll see how.

    Then, we iterate each list and reverse them while iterating! If both iterators reach the merge point at the same time, then we find it out by mere comparing. Otherwise, one pointer will reach the merge point before the other one.

    After that, when the other iterator reaches the merge point, it won’t proceed to the common tail. Instead will go back to the former beginning of the list that had reached merge-point before! So, before it reaches the end of the changed list (i.e. the former beginning of the other list), he will make a+b+1 iterations total. Let’s call it z+1.

    The pointer that reached the merge-point first, will keep iterating, until reaches the end of the list. The number of iterations it made should be calculated and is equal to x.

    Then, this pointer iterates back and reverses the lists again. But now it won’t go back to the beginning of the list it originally started from! Instead, it will go to the beginning of the other list! The number of iterations it made should be calculated and equal to y.

    So we know the following numbers:

    x = a+c
    y = b+c
    z = a+b
    

    From which we determine that

    a = (+x-y+z)/2
    b = (-x+y+z)/2
    c = (+x+y-z)/2
    

    Which solves the problem.

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

Sidebar

Related Questions

This question may have been asked before, but I had trouble finding an answer,
May be this question has been answered before but I couldn't find it. I
This may be a very old, many times asked question. But I am not
This is may be old question but i dont get proper solution if it
This may be an old and trivial question but I have been struggling to
This question may seem trivial, but I hope you won't ignore it. Before destroying
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This question may sound too silly, however , I don't find concrete answer any
I understand that this question may seem somewhat ungrounded, but if someone knows anything
This may be the dumbest question ever but our customer really wants this. I

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.