HCL Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

Step 1: if the linked lists are not empty, find the length of each linked list. Since they have a common end point, we will get length of common area of the linked lists too.
Step 2: find the difference between the length of both list. Start traverse the biggest list till the difference in length between them, provided one of them is bigger than the other.
Step 3: now they are at the same remaining length. Traverse both of the together till both are pointing to the same next node.That node is the common node which is the merging point. If there is no such point, then they are not merged.

- BVarghese April 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public bool findIntersectionof2LinkList()
        {
            curr = Head;
            curr1 = Head1;
            //traverse list 1
            while (curr != null)
            {
                curr.isVisited = true;
                curr = curr.next;
            }

            //traverse list2 and find the intersection
            while (curr1 != null)
            {
                if (curr1.isVisited)
                    return true;
                else
                    curr1 = curr1.next;
            }
            return false;
        }

- Anonymous April 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's good, but only if you can add such a field to the 'Node' class of a given list.

- peruron April 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you could traverse to the end of one of the link lists and then point the last node to start of the list => making it a circular list.

by traversing the other list now, the merging node can be found out from the 'tortoise-hare' algorithm.

- VJ April 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public bool findIntersectionof2LinkList(Node Head, Node Head1)
        {
            Node curr = Head;
            Node curr1 = Head1;
            //traverse list 1
            while (curr != null)
            {
                curr.isVisited = true;
                curr = curr.next;
            }

            //traverse list2 and find the intersection
            while (curr1 != null)
            {
                if (curr1.isVisited)
                    return true;
                else
                    curr1 = curr1.next;
            }
            return false;
        }

- agrajai74 April 19, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More