Given a list of numbers ( fixed list) Now given any other
list, how can you efficiently find out if there is any
element in the second list that is an element of the
first list (fixed list)




Answers were Sorted based on User's Feedback



Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if..

Answer / ajay

@Karan Verma
as stated in the question, you can not sort the first list
(fixed list)

Is This Answer Correct ?    9 Yes 1 No

Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if..

Answer / karan verma

Above method will be most efficient in terms of time
complexity that is O(n).
If we desire space complexity O(1)

--> sort the two lists O(nlogn)
--> find the missing no. O(n)

O(n+nlogn)=O(nlogn)
space complexity=O(1)

Is This Answer Correct ?    11 Yes 7 No

Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if..

Answer / raghuram.a

Use a hash table for storing the no.s of 1st list.
now using hash function check whether there is a no. of 2nd
list in the 1st list.(no. of comparisons=no. of elements in
the list!!efficient?)

Is This Answer Correct ?    7 Yes 5 No



Post New Answer



More C Code Interview Questions

main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


void main() { int const * p=5; printf("%d",++(*p)); }

3 Answers   Infosys, State Bank Of India SBI, Made Easy,


Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

0 Answers   Microsoft,


main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above

5 Answers   HCL,






main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }

1 Answers  


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }

2 Answers   Wipro,


Cluster head selection in Wireless Sensor Network using C programming language.

0 Answers  


main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

1 Answers  


main() { char a[4]="HELL"; printf("%s",a); }

3 Answers   Wipro,


What is the hidden bug with the following statement? assert(val++ != 0);

1 Answers  






Categories