Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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..

@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..

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..

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

More C Code Interview Questions

There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.

How to swap two variables, without using third variable ?

main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }

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

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

main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }

int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }

¦void main() ¦{ ¦int i=10,j; ¦ j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-30 but in same question if we write as- ¦void main() ¦{ ¦int i=10; ¦ int j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-33 why output is changed from 30 to 33. Can any body answer...

Display the time of the system and display the right time of the other country

find A^B using Recursive function

How to return multiple values from a function?

main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }

Categories