Oracle Interview Question for Software Engineer / Developers


Country: -
Interview Type: In-Person




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

// remove duplicates
	// complexity O ( n )
	public static void removeDuplicates(LNode head){
		Hashtable<Integer,LNode> table = new Hashtable<Integer,LNode>();
		if(head == null) return;
		if(head.next == null) return;
		LNode current = head;
		LNode next = current.next;
		table.put(current.value, current); 
		while(next != null){
			if(table.containsKey(next.value)){
				next = next.next;
				current.next = next;
							
			}else{
				table.put(next.value,next);
				current = next;
				next = next.next;
			}
			
		}
	}

// remove duplicates with out an extra buffer.  
// complexity O (n^2) 
	public static void removeDuplicates2(LNode head){
		if(head == null) return;
		if(head.next == null) return;
		
		LNode current = head;
		
		
		while(current != null){
			int currentValue = current.value;
			LNode previus = current;
			LNode next = current.next;
			while(next != null){
				if(next.value == currentValue){
					
					next = next.next;
					previus.next = next;
				}else{
					previus = next;
					next = next.next;
				}
				    
			}
			current = current.next;
		}
	}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Function to remove duplicates from a unsorted linked list */
void removeDuplicates(struct node *start)
{
  struct node *ptr1, *ptr2, *dup;
  ptr1 = start;
 
  /* Pick elements one by one */
  while(ptr1 != NULL && ptr1->next != NULL)
  {
     ptr2 = ptr1;
 
     /* Compare the picked element with rest of the elements */
     while(ptr2->next != NULL)
     {
       /* If duplicate then delete it */
       if(ptr1->data == ptr2->next->data)
       {
          /* sequence of steps is important here */
          dup = ptr2->next;
          ptr2->next = ptr2->next->next;
          free(dup);
       }
       else /* This is tricky */
       {
          ptr2 = ptr2->next;
       }
     }
     ptr1 = ptr1->next;
  }
}

- Nit February 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct listNode
{
	int data;
	struct listNode *next;
};

typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

   void renoveDuplicates(ListNodePtr sptr)
{
	map<int,bool> M;
	ListNodePtr previous=NULL;
	while(sptr!=NULL)
	{
		if(M[sptr->data]==true)
		{
			cout<<"i m here"<<endl;
			previous->next=sptr->next;
		}
		else
		{
			M[sptr->data]=true;
			previous=sptr;
		}
		sptr=sptr->next;
	}
}

- princeladdak February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you do have some memory available, you can use a bit vector and iterate the linked list only once.

1. Create a bit vector with size equal to the max size that a node can store (e.g., if a node stores 32 bit integer values, create a bit vector that is 2^32 bits long - 0.5 GB).
2. Iterate through the linked list. For each node, check if the respective bit is set. If the bit is not set, set it and move to the next node. If the bit is set, make the previous node to point to the next one (i.e., delete the current node) and move to the next node.

- Kostis January 22, 2016 | 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