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 6772227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:31:31+00:00 2026-05-26T15:31:31+00:00

I was asked in an interview this question LinkedList A has {1,2,3,4,5,6} LinkedList B

  • 0

I was asked in an interview this question

LinkedList A has {1,2,3,4,5,6}

LinkedList B has {1,3,5}

I needed to write a method which would return back a Set which does not contain the duplicate elements in list A and B

result { 2,4,6}

I wrote a solution which would iterate over first list and if it does not exist in the second list then add it to a HashSet. But need a solution which performs better than the suggested Algorithm.

No space constraint mentioned for solving this.

Would definitely like a solution using JDK ,but would prefer a solution which is algorithm based

Thanks a ton

  • 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-05-26T15:31:32+00:00Added an answer on May 26, 2026 at 3:31 pm

    The standard solution is to loop through the first list and put everything in a hash table. This is linear time since inserting into a hash table is constant time.

    Then loop through the second list and look to see if each element exists in the hash table. If it exists, delete it from the table. Else, add this item to a new list.

    Now append everything left in the hash table to the new list.

    This second operation is also linear since lookup and deletion are also constant for hash tables. Thus, the overall algorithm is linear.

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

Sidebar

Related Questions

In an interview this is the question that is asked: You have to write
This question was asked in an interview, let me know if anyone does know,
Got asked this interesting interview question today. Explain in detail the process by which
I was asked this question in interview. Which of the following is better to
I was asked this question in some interview. I was required to write code
I was asked this as interview question. Couldn't answer. Write a C program to
Hii , I was asked this question in a recent interview for which i
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
I was asked this question in a job interview. The interviewer and I disagreed
I was asked this question during an interview. They're both O(nlogn) and yet most

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.