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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:27:53+00:00 2026-05-31T19:27:53+00:00

I am solving the problem in the interview question about LinkedList. question is… Write

  • 0

I am solving the problem in the interview question about LinkedList.

question is…

Write code to remove duplicates from an unsorted linked list
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?

I was reading the solution and I dont understand three parts in the solution.

First,

public static void deletedup(LinkedListNode n) 
{
     Hashtable table = new Hashtable();
     LinkedListNode prev = null;
     while(n != null)
     {
         if(table.containsKey(n.data))
          prev.next = n.next; //<--
          else
          table.put(n.data, true);
          prev = n;//<--
      }
       n =  n.next;
}

First-1 question.
In the solution, if table contains the duplicated keyword. they have move to next node.
I was thinking the we just need to to n = n.next. However, solution was doing prev.next= n.next;. However, we don’t really sure prev in the code. Why do we have to use prev ?
Moreover,
after putting unique keyword in the table solution assign n to prev (prev = n;). Why do we have to do it ?

Second,

public static void deletedup(LinkedListNode head)
{ 
LinkedListNode pre = head;
LinkedListNode cur = pre.next;
while(cur != null){ 
  LinkedListNode runner =head;
while(runner != current)
{
  if(runner.data == cur.data)
  { 
      LinkedListNode tmp = current.next;
      pre.next = tmp;//<---
      current = tmp;//<--
      break;
  }
  [...]
}

[...]
}
}

Second question , from the second solution , it program find the duplicated keywords, we have to remove it. Therefore, they declare tmp node to remove to remove duplicated keyowrds.
However, I don’t really understand the reason to do ” pre.next = tmp and cur = tmp”.
I am guessing thet “cur = tmp” will update the current to next node. However, I am not really sure about the reasons..

Third, for the Big o part . I am assuming that first solution will be O(n) and second solution will be O(n^2). Is it right ?

thanks

  • 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-31T19:27:55+00:00Added an answer on May 31, 2026 at 7:27 pm

    First Question:
    n is a reference to a node. It is a local reference that is only valid in this function.

    Say we are accessing the linked list in the future.
    The way a node is discovered is by the reference ‘r’ located in the previous node. We need to change that reference. If we change n, it will not make any difference to ‘r’.

    If you’re from the C/C++ world, think of n as being like a unique pointer to a node. Will changing the value of this pointer change the value of ‘r’? I think not.

    Second Question:
    I think your doubt here might be related to assignments. WHen we say ‘current.next’, we are referring to the ‘next’ variable in object ‘current’. We are not saying, ‘advance current to the next node’. That is why ‘current.next’ will not really change any variables. When we say ‘current = current.next’, we are saying, okay, i want to change the node that ‘current’ is pointing to, and i want to change it to ‘current.next’, the next node.

    Also, I believe you are right about the complexity.

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

Sidebar

Related Questions

I was stuck in solving the following interview practice question: I have to write
I am about to spend a lot of time solving a problem, and I
I have more of a 'problem solving' question than a syntax related problem. Briefly,
Summary: How would I go about solving this problem? Hi there, I'm working on
i was solving the problem https://www.spoj.pl/problems/ACPC11A/ and here is my code : #include<iostream> #include<cstdio>
I'm stuck with the JavaScript code I am using for solving a problem which
I need help solving problem N from this earlier competition : Problem N: Digit
I am solving this problem of rotating an array and got algorithm and code
I am solving a problem of transferring images from a camera in a loop
This question comes after solving the problem I got in this question . 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.