Goldman Sachs Interview Question for Software Engineer / Developers






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

T1=0123456789
T2=6210001000

for (int i = 1; i< 10000000; i++){
int temp2 = i;
for (int j = 0; j<10 ; j++) {
Temp[j] = temp2%10;
temp2 = (int)(temp2/10);
}
//output(Temp);
if ( count(Temp,T1[0])==Temp[0] &&
count(Temp,T1[1])==Temp[1] &&
count(Temp,T1[2])==Temp[2] &&
count(Temp,T1[3])==Temp[3] &&
count(Temp,T1[4])==Temp[4] &&
count(Temp,T1[5])==Temp[5] &&
count(Temp,T1[6])==Temp[6] &&
count(Temp,T1[7])==Temp[7] &&
count(Temp,T1[8])==Temp[8] &&
count(Temp,T1[9])==Temp[9]) {

output(Temp);
continue;
}
}
System.out.println(" finish ");

- pengzhang130 April 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I tried to get the logic but couldn't find out. Plz explain the logic in words.

- Anonymous February 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@pengzhag: that was awesome! thanks.

- xankar July 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Problem:
================
For 0<=i<=9,
array defined is T1[i] = i .
Now construct another array T2[j]
for 0<=i<=9
where T2[j]==m
if T1[i] appears m times in T2[j].

Example:
================
T1[123456789]
where SIZE1=9

T2[111123456]
SIZE BASED ON M=4



ALGO:
================
FOR EACH T1[I] CHECK ALL T1[J] VALUES AND INCREASE THE COUNT
COMPARE THE COUNT WITH M
IF COUNT==M THEN
ENTER ALL THE VALUES IN T2[]
ELSE REPEAT


CODE:
================

PRIVATE ARRAY CONSTRUCTARRAY(ARRAY T1[] , INT SIZE)
{
FOR(INT I=0;I<SIZE-1;I++)
{
FOR(INT J=0;J<SIZE-1;J++)
{
IF(T1[I]==T1[J])
{
COUNT++;
INT ELEMENT=T[I];
}
}
IF(COUNT==M)
{
FOR(K=O;K<M;K++)
{
T2[K]=ELEMENT;
}
}
}
RETURN T2[K];

}



ORDER:
================
O(N^2)

- Tarun Phaugat March 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think u hav not understood the question.
It's simple like count sort

- bond July 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In you example, T2[9]==6, m = 4, and I am not able to relate them together.
Can you break it down by , writng the elements sperately? Eg: T2[1]=1 , T2[2]=...
Something is not right. How did you assume m=4?

- xankar March 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well you can also use "inplace counting sort" also

- ridercoder November 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ridercoder
sorry, couldn't understand how would you use inplace counting sort. Above algo seems perfect..

- rahul February 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

8100000000
9000000000

- Ajit May 11, 2012 | 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