Goldman Sachs interview prep
8 practice questions on the topics candidates reported from Goldman Sachs interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
Which data structure is the natural fit for checking whether brackets like ([]{}) are balanced?
- A stack
- A queue
- A hash set
- A binary search tree
Show the answer
A. A stack
Push each opening bracket. Each closing bracket must match the bracket on top, which is popped. The string is balanced if every bracket matched and the stack ends empty.
This topic is named in a candidate’s interview report: Summer internship interview, 2020, on GeeksforGeeks.
-
You merge n sorted arrays of k elements each into one sorted array, using a min-heap that holds the smallest unused element of each array. What is the time complexity?
- O(nk log n)
- O(nk log nk)
- O(nk)
- O(n^2 k)
Show the answer
A. O(nk log n)
There are nk elements, and each is pushed and popped once on a heap of at most n entries, O(log n) each. Joining the arrays and sorting everything would cost O(nk log nk).
This topic is named in a candidate’s interview report: Summer internship interview, 2020, on GeeksforGeeks.
-
How can you reverse a queue without a second queue or an explicit stack?
- Dequeue each element and enqueue it again once
- Recursively: dequeue the front, reverse the rest, then enqueue the saved element at the back
- Sort the queue in descending order
- It cannot be done
Show the answer
B. Recursively: dequeue the front, reverse the rest, then enqueue the saved element at the back
The call stack acts as the stack: each call holds one element until the deeper calls finish, so the first element taken out goes back in last. It uses O(n) stack space. With only a second queue it can be done too, but in O(n^2) moves.
This topic is named in a candidate’s interview report: On-campus internship interview, on GeeksforGeeks.
-
An undirected graph has 7 edges. What is the sum of the degrees of all its vertices?
- 7
- 49
- It depends on the number of vertices
- 14
Show the answer
D. 14
Every edge adds 1 to the degree of each of its two ends, so the degrees always add up to twice the number of edges (the handshaking lemma). It follows that the number of vertices with an odd degree is always even.
This topic is named in a candidate’s interview report: On-campus internship interview, on GeeksforGeeks.
Python 1
-
Which statement about C++ and Python (the standard CPython) is true?
- Python checks types at compile time and C++ only at run time
- C++ is compiled to machine code before it runs; CPython compiles to bytecode and interprets it, so plain Python loops are usually much slower
- C++ frees memory automatically with a garbage collector and Python does not
- Both run on the Java virtual machine
Show the answer
B. C++ is compiled to machine code before it runs; CPython compiles to bytecode and interprets it, so plain Python loops are usually much slower
C++ checks types when it compiles and runs as native code. Python checks types as it runs and frees memory by counting references. Libraries such as NumPy are fast because their inner loops are written in C.
This topic is named in a candidate’s interview report: Summer internship interview, 2020, on GeeksforGeeks.
DBMS and SQL 1
-
emp has 4 rows in dept "eng", 2 in "ops" and 3 in "hr". Which departments does this return?
SELECT dept FROM emp GROUP BY dept HAVING COUNT(*) > 2 ORDER BY dept;- eng, hr and ops
- eng only
- eng and hr
- hr and ops
Show the answer
C. eng and hr
GROUP BY makes one group per department and HAVING filters the groups by their count. eng (4) and hr (3) have more than 2 rows; ops (2) does not.
This topic is named in a candidate’s interview report: Summer internship interview, 2020, on GeeksforGeeks.
Software engineering 1
-
What is a branch in git, technically?
- A full copy of every file in the repository
- A separate repository on the server
- A movable pointer to a commit, which moves forward as you commit on it
- A backup git makes before each commit
Show the answer
C. A movable pointer to a commit, which moves forward as you commit on it
A branch is a small file holding one commit id, and HEAD records which branch you are on. That is why creating or switching a branch in git is instant, unlike older systems that copied files.
This topic is named in a candidate’s interview report: On-campus internship interview, on GeeksforGeeks.
Aptitude 1
-
Two ropes each take exactly 60 minutes to burn, but they burn unevenly, so half a rope does not take 30 minutes. How do you measure exactly 45 minutes?
- Light rope A at both ends and rope B at one end; when A burns out, light the other end of B, which burns out 15 minutes later
- Cut each rope in half and burn the pieces one after another
- Light both ropes at one end and stop when three quarters of A has burned
- Light rope A at both ends, then rope B at both ends
Show the answer
A. Light rope A at both ends and rope B at one end; when A burns out, light the other end of B, which burns out 15 minutes later
A rope lit at both ends burns out in half its time, whatever its shape. When A is gone, 30 minutes have passed and B has 30 minutes left; lighting B's other end halves that to 15. 30 + 15 = 45.
This topic is named in a candidate’s interview report: On-campus internship interview, on GeeksforGeeks.