is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
This is O(n). I am traversing the list only once and no extra space. But the problem is this code works for numbers less than 32. With a little sensible modifications it can be made to work for the greater numbers. I might be wrong about O(n) but for sure traversing it only once. Positive and worthwile suggestions are welcome :)
- swpnl.borse June 13, 2014// Program to remove the duplicate elements from the linked list //
#include<stdio.h>
#include<stdlib.h>
struct node{
int no;
struct node* next;
};
typedef struct node* Nodep;
Nodep makeLinkedList(int);
void printList(Nodep);
int main(){
int i,num,t=0;
printf("How many nodes you want in the linked list??\n");
scanf("%d",&num);
Nodep head = makeLinkedList(num);
Nodep temp = head;
Nodep p = head->next;
t = t|1<<(head->no-1);
while(p!=NULL){
if(t&1<<(p->no-1)){
p = p->next;
if(p == NULL){
temp->next = NULL;
break;
}
}
else if(temp->next == p){
temp = temp->next;
t = t | 1<<(p->no-1);
p = p->next;
}
else{
temp->next = p;
t = t | 1<<(p->no-1);
if(p->next == NULL){
temp->next = p;
}
temp = p;
p = p->next;
}
}
printf("\nThe linked list after removing duplicate nodes is:\n");
printList(head);
return 0;
}
Nodep makeLinkedList(int n){
int exec = 1,i;
Nodep start,p;
printf("Enter the numbers:\n");
for(i = 0;i<n;++i){
if(exec){
p = (Nodep)malloc(sizeof(struct node));
start = p;
p->next = NULL;
scanf("%d",&p->no);
exec = 0;
}
else{
Nodep q = (Nodep)malloc(sizeof(struct node));
q->next = NULL;
scanf("%d",&q->no);
p->next = q;
p = p->next;
}
}
return start;
}
void printList(Nodep head){
while(head->next!=NULL){
printf("%d ",head->no);
head = head->next;
}
printf("%d",head->no);
}