Goldman Sachs Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

package pank.com.org;


public class MyOwnHashMap {

private final static int size =16;
private Entry table[]= new Entry[size];

static class Entry
{
final String key;
String value;
Entry next;

public Entry(String K, String V) {
key=K;
value=V;
}

public void setValue(String value)
{
this.value= value;

}


public String getKey()
{
return this.key;
}
public String getValue()
{
return this.value;
}
}

public Entry get(String key)
{
int hash = key.hashCode()%size;
Entry e= table[hash];
while(e!=null)
{
if(e.key.equals(key))
{
return e;
}
e = e.next;
}
return null;


}

public void put(String key, String value)
{
int hash = key.hashCode() % size;
System.out.println(key.hashCode());
Entry e = table[hash];
if(e!=null){
if(e.key.equals(key))
{
e.value=value;
}
else
{
while(e.next!=null)
{
e=e.next;
}
Entry oldEntry = new Entry(key,value);
e.next= oldEntry;
}
}
else
{
Entry newEntry = new Entry(key,value);
table[hash]=newEntry;
}
}



public static void main (String args[])
{
MyOwnHashMap map= new MyOwnHashMap();
map.put("Chandu", "SMTS");
map.put("Shan", "SMTS");
map.put("Chanda", "SSE");
map.put("Niranjan", "SMTS1");
map.put("Chandu", "SSE");

Entry e= map.get("Chandu");
System.out.println( "key>>>>" +e.getKey());
System.out.println("value >>>>"+ e.getValue() );
System.out.println( "class>>>>" + e.getClass());
System.out.println("Hascode"+e.hashCode());

Entry e1= map.get("Niranjan");
System.out.println( "key>>>>" +e1.getKey());
System.out.println("value >>>>"+ e1.getValue() );
System.out.println( "class>>>>" + e1.getClass());
System.out.println("Hascode"+e1.hashCode());
}
}

- own hashMap August 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hashmap can we build using arrays and linked list.

- DashDash January 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package pank.com.org;


public class MyOwnHashMap {
private final static int size =16;
private Entry table[]= new Entry[size];
static class Entry
{ final String key;
String value;
Entry next;

public Entry(String K, String V) { key=K;
value=V; }

public void setValue(String value){
this.value= value; }
public String getKey() {
return this.key;
}
public String getValue()
{ return this.value;
} }
public Entry get(String key)
{ int hash = key.hashCode()%size;
Entry e= table[hash];
while(e!=null)
{
if(e.key.equals(key))
{ return e;
} e = e.next;
}return null;
}

public void put(String key, String value)
{ int hash = key.hashCode() % size;
System.out.println(key.hashCode());
Entry e = table[hash];
if(e!=null){if(e.key.equals(key)){
e.value=value;}else
{while(e.next!=null){e=e.next;
}
Entry oldEntry = new Entry(key,value);
e.next= oldEntry;}
}
else{Entry newEntry = new Entry(key,value);
table[hash]=newEntry;}
} public static void main (String args[])
{
MyOwnHashMap map= new MyOwnHashMap();
map.put("Chandu", "SMTS");
map.put("Shan", "SMTS");
map.put("Chanda", "SSE");
map.put("Niranjan", "SMTS1");
map.put("Chandu", "SSE");
Entry e= map.get("Chandu");
System.out.println( "key>>>>" +e.getKey());
System.out.println("value >>>>"+ e.getValue() );
System.out.println( "class>>>>" + e.getClass());
System.out.println("Hascode"+e.hashCode());
Entry e1= map.get("Niranjan");
System.out.println( "key>>>>" +e1.getKey());
System.out.println("value >>>>"+ e1.getValue() );
System.out.println( "class>>>>" + e1.getClass());
System.out.println("Hascode"+e1.hashCode());
}
}

- own hashMap August 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package pank.com.org;


public class MyOwnHashMap {
private final static int size =16;
private Entry table[]= new Entry[size];
static class Entry
{ final String key;
String value;
Entry next;

public Entry(String K, String V) { key=K;
value=V; }

public void setValue(String value){
this.value= value; }
public String getKey() {
return this.key;
}
public String getValue()
{ return this.value;
} }
public Entry get(String key)
{ int hash = key.hashCode()%size;
Entry e= table[hash];
while(e!=null)
{
if(e.key.equals(key))
{ return e;
} e = e.next;
}return null;
}

public void put(String key, String value)
{ int hash = key.hashCode() % size;
System.out.println(key.hashCode());
Entry e = table[hash];
if(e!=null){if(e.key.equals(key)){
e.value=value;}else
{while(e.next!=null){e=e.next;
}
Entry oldEntry = new Entry(key,value);
e.next= oldEntry;}
}
else{Entry newEntry = new Entry(key,value);
table[hash]=newEntry;}
} public static void main (String args[])
{
MyOwnHashMap map= new MyOwnHashMap();
map.put("Chandu", "SMTS");
map.put("Shan", "SMTS");
map.put("Chanda", "SSE");
map.put("Niranjan", "SMTS1");
map.put("Chandu", "SSE");
Entry e= map.get("Chandu");
System.out.println( "key>>>>" +e.getKey());
System.out.println("value >>>>"+ e.getValue() );
System.out.println( "class>>>>" + e.getClass());
System.out.println("Hascode"+e.hashCode());
Entry e1= map.get("Niranjan");
System.out.println( "key>>>>" +e1.getKey());
System.out.println("value >>>>"+ e1.getValue() );
System.out.println( "class>>>>" + e1.getClass());
System.out.println("Hascode"+e1.hashCode());
}
}

- Deloas August 27, 2015 | Flag Reply


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