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

#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.

5 Answers   Amazon, Microsoft,


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

9 Answers   Microsoft,


main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }

1 Answers  


void main() { static int i=5; if(--i){ main(); printf("%d ",i); } }

1 Answers  






typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }

1 Answers  


main() { static int var = 5; printf("%d ",var--); if(var) main(); }

1 Answers  


main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


what is oop?

3 Answers  


write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

0 Answers   TCS,


why java is platform independent?

13 Answers   Wipro,


Categories