## Ebay Interview Question for SDE-2s

Team: Traffic
Country: United States
Interview Type: In-Person

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

Shouldn't it be public Object get(Object key) ?

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

yes its public object get(object key)

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

There are at least two ways to implement this: one with linear probing and another one with separate chaining. Here is the version for separate chaining in Java. This also assumes that the key is actually the integers. It will break if the keys are not in integers.

``````package com.practice.hashtable.separatechaining;

public class SeparateChainingExample {
public static void main(String[] args) {
SeparateChainingExample sce = new SeparateChainingExample();

// Test Hash Table

lht.put(0, "A");
lht.put(1, "B");
lht.put(2, "C");
lht.put(3, "D");
lht.put(4, "E");
lht.put(5, "F");
lht.put(6, "G");
lht.put(7, "H");
lht.put(13,"I");
lht.put(21, "J");

sce.testPrint(lht.hashTable);
}

int counter = 0;
System.out.println("NODE #" + counter + " SIZE: " + lhe.getSize());
while((entry != null)) {
System.out.println("\t" + entry.getKey() + " , " + entry.getValue());
entry = entry.getNext();
}
++ counter;
}
}

private final static int TABLE_SIZE = 5;

for(int i=0; i < TABLE_SIZE; ++ i) {
hashTable[i] = null;
}
}

public void put(Object key, Object value) {
int hashValue = ((Integer)(key) % TABLE_SIZE);

if(hashTable[hashValue] == null) {
}
else {
while((entry.getNext() != null) && (!entry.getKey().equals(key))) {
entry = entry.getNext();
}
if(entry.getKey().equals(key)) {
entry.setValue(value);
}
else {
}
}

}

public Object get(Object key) {
int hashValue = ((Integer)(key) % TABLE_SIZE);
if(hashTable[hashValue]  == null) {
return null;
}
else {
while((entry != null) && (!entry.getKey().equals(key))) {
entry = entry.getNext();
}
if(entry == null) {
return null;
}
else {
return entry.getValue();
}
}
}
}

private Object key;
private Object value;
private int size;

/**
* Default Constructor
*/
public LinkedHashEntry(Object key, Object value) {
this.key = key;
this.value = value;
this.next = null;
this.size = 1;
}

public void setKey(Object key) {
this.key = key;
}
public Object getKey() {
return key;
}
public void setValue(Object value) {
this.value = value;
}
public Object getValue() {
return value;
}
this.next = next;
++ size;
}
return next;
}
public int getSize() {
return size;
}

}
}``````

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

Trying to be creative...

``````Public class HashMap
{
Public void put(Object key, Object value) {
// serialize value to a file called "key.id"
}

Public object get(Object key) {
// check if file called "key.id" exists
// if so, deserialize its content and return it
// else return null
}

}``````

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

Creative indeed. Deserves the Interviewee Darwin Award.

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.

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