HCL Interview Question for Java Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

How are hash tables compared. Is it values with the same keys or what?

- DashDash May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you please provide an example. Is it that value in key of one hash table needs to be compared to value in every key in other hash table?

- DashDash May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Get keys from hash_table_1.
Get keys from hash_table_2.
Get keys from hash_table_3.
Create hash_table_4 with chaining.

For each keys in hash_table_1:
value = hash_table_1[key]
hash_table_4[val]

For each keys in hash_table_2:
value = hash_table_2[key]
hash_table_4[val] = 2

For each keys in hash_table_3:
value = hash_table_3[key]
hash_table_4[val] = 3

Get keys from hash_table_4:
count = 0
while hash_table_4[key].pop != NULL
count++
if count == 3
print Common value! Print value here.
count = 0

- Anonymous May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for each key in hashtable1
if exist hashtable2[i]==hash2(key) && hashtable3[i]==hash3(key)
then put key in hashtable4

- Sylla May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

here's the algorithm:
----
For each key in Hashtable1 do following
Insert in Hashtable4
// now hashtable is same as hashtable1
For each key in Hashtable4 do following
if key is not present in Hashtable2 Delete key from hashtable4
// now you have elements in hashtable4 which are common in hashtable1 and 2
For each key in Hashtable4 do following
if key is not present in Hashtable3 Delete key from hashtable4
// now you have elements in hashtable4 which are common in hashtable1, hashtable2 and hashtable3.

- VJ May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public Hashtable<Integer,Integer> commonHashTable(Hashtable<Integer,Integer> t1, Hashtable<Integer,Integer> t2 , Hashtable<Integer,Integer> t3){

Hashtable<Integer,Integer> t4 = new Hashtable<Integer,Integer>(t1);
Set<Integer> s = t4.keySet();
Iterator<Integer> itr = s.iterator();
while(itr.hasNext()){
Integer t = itr.next();
if(!t2.containsKey(t) || !t3.containsKey(t))
itr.remove();
}
return t4;
}

- Rahul Khanna May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This requirement looks like to have the intersection for three hash table. Use Java Set can get it.

public static Set<Integer> threeSetIntersection(Set<Integer> set1, Set<Integer> set2, Set<Integer> set3) {
    
    Set<Integer> tempSet1 = new HashSet<Integer>(set1);
    Set<Integer> tempSet2 = new HashSet<Integer>(set1);
    
    tempSet1.retainAll(set2);
    tempSet2.retainAll(set3);
    
    tempSet1.retainAll(tempSet2);
    
    return tempSet1;
  }

- jbai_98@yahoo.com May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Find the first two smallest of the three tables.
2. Search the elements of the smallest table in the smaller table of the two and save the common values between the two -> O(Size_Of_Smallest_array)
3. Search the saved values in the largest table and print those that are found in this last table -> O(Size_Of_Array_Common_Between_Two_Smallest_Tables).

- Anonymous May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

compare 2 smallest HT's, put common in 4th. check if common is in third ht, if present keep else remove.

- bot23 September 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

@DashDash compared with different key

- amit.grynch May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

@DashDash yes,key of one hashtable will compared with key of ohter two hashtable, if same key is dere ,store that key with corrosponding value in 4rth table..

- amit.grynch May 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you be clearer? What you wrote makes it very hard to understand the problem. What is "dere.store"? Read what you write before posting it.

- liu425 May 21, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More