Goldman Sachs Interview Question for Software Engineer / Developers






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

Create a tree with these numbers and also keep the freq of each number at every node
Now do an inorder traversal to print only those with freq 1

Time complexity : nlogn

- DashDash August 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

O(logn), not O(nlogn)

- Anonymous January 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think sorting the linked list and then returning the distinct numbers is better than maintaining a BST for that . There are 2 reason ->

1. Extra memory used to maintain the BST .
2. Worst case runtime : O(n^2)

- Frodo Baggins August 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about using a hash.

- Manoj August 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Set distinctLst=new HashSet(List);

- Jigs August 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.HashSet;
import java.util.Set;

public class MainClass {
public static void main(String args[]) {
String[] name1 = { "Amy", "Jose", "Jeremy", "Alice", "Patrick" };

String[] name2 = { "Alan", "Amy", "Jeremy", "Helen", "Alexi" };

String[] name3 = { "Adel", "Aaron", "Amy", "James", "Alice" };

Set<String> letter = new HashSet<String>();

for (int i = 0; i < name1.length; i++)
letter.add(name1[i]);

for (int j = 0; j < name2.length; j++)
letter.add(name2[j]);

for (int k = 0; k < name3.length; k++)
letter.add(name3[k]);

System.out.println(letter.size() + " letters must be sent to: " + letter);

}
}

- Anonymous September 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hash is best in this case, O(n)
Insert into hash with key = number and data = key.count++, //initially count is zero
if count>1 then dont print because it is already inserted and printed.

- chennavarri October 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't have to maintain the data( count), HashSet wont allow duplicate key anyways.
Using HashSet is good. Because creating BST will also take memory. and complexity is also n(logn).

But if you need to iterate through those unique elements then better u should use BST. Because if Hash Code is not good then HashSet can behave very badly.

- Piyush November 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't have to maintain the data( count), HashSet wont allow duplicate key anyways.
Using HashSet is good. Because creating BST will also take memory. and complexity is also n(logn).

But if you need to iterate through those unique elements then better u should use BST. Because if Hash Code is not good then HashSet can behave very badly.

- Piyush November 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort - n(logn).
Iterate over the sorted list and track the value of the previous element. if previous==current, do not display the value.

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

def fun(arr):
       dict = default(int)
       for element in arr:
           dict[element] +=1
       for element in dict:
           if dict[element] == 1:
              print element

- weijiang2009 February 06, 2011 | 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