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

why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

0 Answers  


main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }

5 Answers  


Is it possible to type a name in command line without ant quotes?

1 Answers   Excel, Infosys,


void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above

1 Answers   HCL,


#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q); }

1 Answers  






main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

1 Answers  


Given n nodes. Find the number of different structural binary trees that can be formed using the nodes.

16 Answers   Qualcomm, Directi, Cisco, Aricent,


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

0 Answers  


main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

1 Answers  


main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }

29 Answers   IBM, TCS, Wipro, UGC NET,


main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

2 Answers  


C statement to copy a string without using loop and library function..

2 Answers   TCS, Persistent,






Categories