Goldman Sachs Interview Question
556 Interview Reviews |
Back to all Goldman Sachs Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Developer at Goldman Sachs:
Write a program to find the common characters in two strings. After writing the code they asked to reduce the complexity.
See more for this Goldman Sachs Software Developer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (1)
Members can
answer or comment on this question
–
Join Now (It's Free) or
Sign In



0 of 0 people found this helpful
by blue:
Create a first array of chars that contains the characters of the first string sorted by ascii code. [d,i,n,o, s,w, w]. Let's name this array A
Create a second array of chars that contains the characters of the second string sorted by ascii code. [i, l, n, u ,x]. Let's name this array B.
The pseudo algorithm will be as follow:
posA = 0
posB = 0
while(posA < A.length && posB < B.length) {
if (A[posA] == B[posB]) {
print "find common character = " + A[posA];
posA++;
posB++;
} else if (A[posA] < B[posB]) {
posA++;
} else {
posB++;
}
}