Goldman Sachs Interview Question for Software Engineer / Developers






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

1) ++a is faster.
2) a constructor with one argument is an implicit constructor.
4) Things that run before main enter would be Static Variable Initializations. Check on that.
5) F2() might through an exception and delete x might never be called
6)copy

- vodangkhoa March 10, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

1) ++a means increment & use. a++ means use & increment. i.e use the same value and then increment. This means a temporary is created to hold & use the same value. While a is incremented. So, ++a is faster & it is always better practice to use ++a

2) A constructor a) with one parameter or b) which has at least one default parameter can do implicit conversions

A) MyClass1( int num );
B) MyClass1( const MyClass1 &irOther);

MyClass1 ob1 = 15; // convert 15 to an instance of MyClass1 using 1st then call copy constructor i.e 2nd one to make this call succeed.

C) MyComplexNumber( double iReal, double iImaginary = 0);
D) MyComplexNumber( MyComplexNumber );

double realval = 15;
MyComplexNumber obj2 = realval; // we do not specify any impaginary here. Compiler converts realval to an object of type MyComplexNumber using C). Then calls D) to create obj2

Its a good practice to use the keyword 'explicit' with your constructors so that such implicity conversions can be checked.
A) explicit MyClass1( int num );
C) explicit MyComplexNumber( double iReal, double iImaginary = 0);

3) String::copy works on only string types. For memcopy the underlying type is irrelevant. It is a binary copy of the data.

4) Global & static variables

5) F2() has to assume that x has been newed i.e F1() has been called. This results in dependency of F2() on F1(). The design is flawed. If F1 throws an exception, F2 may not be called & memory for x cannot be reclaimed as long as the program is running.

6) Copy by value. There is no alternative
A) i + j;
B) k = i + j;

This calls operator + (a, b). You do not want to use the value of i as the final result. i should remain as it is !!

You have to create a temporary object from i (or j) using copy constructor. Add the data member values of j to the data member of temp. Return temp.

Note- It is always a better practiceto implement non-member function operator + (a,b) in terms of class member function operator += (b) for localiziing the core logic.

- The Hercules February 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) generally ++a would be implemented as:
{
a = a + 1;
return a;
}
and a++ would be
{
b = a;
a = a + 1;
return b;
}
so a++ does more.

4) static variable, global variable...

6)return the reference. However when using a = b + (c), the assignment will invoke the assignment operator.

- adon September 28, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just use gcc -S to generate assembly code for ++a and a++ on Red Hat Linux. I found the generated the same assembly instruction. So, I think it is compiler dependent, which one is faster because on my Linux machine, it is the same.

- puzzle October 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you have a class with an overloaded ++ operator, then you might see the difference. An optimizing compiler will likely optimize i++ and ++i to be the same if the resulting value of the statement is unused and i is a primitive type.

- Anonymous May 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

1)they are the same
2)....
3)terminator \0 used in stringcopy and the bytes specified in memcopy
4)depends
5)possibly if u pass x to F2 and delete it there then on return deleting again can giv u a runtime error
6)ref..

- ska March 10, 2007 | 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