in JAVA by
Q:
Goldman Sachs Interview Questions for Java Developer

1 Answer

0 votes
by

Core Java Questions Asked in Goldman Sachs Interview

1) What is difference between JDK, JRE, JVM?

2) How will you implement multiplication for very big numbers without using Java inbuilt classes?

3) How will you implement your own hashmap in Java? How will you handle collision of keys? Basically 

interviewer wants to know internals of a hashing data structure.

4) What are the main interfaces in Java Collections framework? What is difference between Set and List?

5) Why strings are immutable? how many objects will be created in String temp = "A" + "B" + "C" ; explain your answer in detail. Hint- Role of Immutable Objects in writing thread safe scalable applications.

6) Differences between Arrays and Linked Lists. In which situation, you would choose one over the other?

7) Concept of OOPS : Encapsulation, Data Hiding, Abstraction, Polymorphism etc.

Java Coding Problems in Goldman Sachs Interview

There is a String array String[] words = {"hello", "world", "HELLO", WORLD"}; How will you print output like hello-2, world-2 i.e. word followed by its count ignoring the case of the words in the input Array?

Given a string check if the string is palindrome or not?

There is a array of words String[] words = {"abc","bca", "cab", "cba", "def", …​} etc. So if given an input "cab", your program should print all the words that contains 'c', 'a' and 'b' i.e. "bca", "abc", "cba", etc. How will you achieve that? Anagrams example?

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is “yyyybbbbdexxxxxxx”, then the function should return “y4b4dex7″.

Let’s say I gave you a long String and I wanted you to tell me the most common word in that String. How would you do that?

follow-up: OK, how would you estimate the size and time complexity of this solution? How would you estimate the ACTUAL size usage? (Hint: how many words are in the English language? Would having a dictionary in front of you help?)

follow-up #2: OK, how about if I gave you the entire works of Alexandre Dumas, one of the most prolific authors in history. How would your solution work? How could you change it to solve this more specific problem?

follow-up #3: Now, what if we wanted to find the most common PHRASE in his writings. (Upon clarification, the interviewer wouldn’t give a specific length, so I clarified to finding as long as a common 10 word phrase, because anything longer is unlikely.)

Hint - Find Top X occurring words in a very big file using Min-Heap and Hashtable.

How will you reverse a linked list in Java?

How will you find common ancestor of two given nodes A and B in a binary Tree?

How reverse key index helps in faster data reading and what is use case for this? Complexity of B tree index?

Implement queue using Stacks.

implement the queue using only 1 stack

Data structure and Algorithms

What is a Binary Search Tree?

Write a program to check whether a binary tree is BST or not.

In a client-server architecture, there are multiple requests from multiple clients to the server. The server should maintain the response times of all the requests in the previous hour. What data structure and algo will be used for this? Also, the average response time needs to be maintained and has to be retrieved in O(1).

Find minimum element in stack. Optimized solution is required.

Check if a linked list is palindrome or not

Performance

You have 5 data sources. There is a program which calls these data sources and returns a count value. You need to speedup this program. How do you do that? This is a sample code

int count = getCount(ds1);

if(count < 100 )

count = count + getCount(ds2);

if(count < 100)

count = count + getCount(ds3);

if(count < 100)

count = count + getCount(ds4);

if(count < 100)

count = count + getCount(ds5);

Hint - Interviewer must be looking for multi-threading. Fetch count from all sources in parallel. Bonus points: If machine has less than 5 cores (for 5 data sources), say 4 cores, prioritize so that first 4 cores get the highest priority. Not sure how to do this in code.

Design Problems

How would one design a multi format converter that supports reading data from multiple data sources(web service, local disk, etc.). The data from the sources can be in multiple formats. The reader for each format may be different and how does one serialize this abstract data to multiple formats like image, xml etc. New readers, writers and data sources can be added later during implementation.

Hint: Design Patterns problem, look for java.io.* classes for example Reader, InputStream, etc. Decorator Design pattern. There are two variables here - 1. Multiple Datasources with common interface 2. Multiple formats with common interface. 9implementation can be provided later on. our APi should be coded over interface rather than implementation.

How will you design a connection pool in Java?

Testing

Different testing concepts. What is unit testing, integration testing, regression testing? What is the need for each one of them?

The testing discussion lead to environments discussion. I mentioned production and test environments in my answers. So they started discussing the need for so many environments for a same application.

If we give you a particular feature to add to an application, how will you do it? How will you document it, test it? How will you take it through different environments of the application?

Another Interview At Goldman Sachs :

Online coding round (Hackerrank): 2 easy coding questions; Time: 120 minutes

Game of Book Cricket.

Simple string encoding-decoding problem. https://leetcode.com/discuss/interview-question/334671/goldman-sacks-july-2019-hackerrank-2

After clearing the online test, resume shortlisting takes place and if your resume is shortlisted, further rounds will be conducted.

Round 1 (Coderpad + voice call): Two easy-medium level questions were discussed and you need to write the complete runnable call and pass all the test cases.

Given a String and two words (which occur in the given string), find the minimum distance between two words. Distance between two words is defined as the number of characters between the given two words’ middle characters. The brute-force approach was already implemented but it had some logical bugs, and because of which sample test cases were failing. The objective was to find and fix those bugs and then to add some new test cases and write a code for those test cases as well.

Simple DFS + DP in a 2D matrix to find the minimum cost path.

Note: Round 2 – 6 (Each round took around 60-70 minutes, all rounds were on the same day, Zoom Video Call + Coderpad):

Round 2(DSA):  

Quick introduction

Find the difference between two arrays: Two unsorted arrays are given, and you need to find (arr1 – arr2) and (arr2 – arr1). The difference between the two arrays is defined as all the elements from the first array which are not present in the second array, taking the number of occurrences into consideration.

Example:

arr1: [3, 5, 2, 7, 4, 2, 7] arr2: [1, 7, 5, 2, 2, 9]

arr1 – arr2 = [3, 7, 4]

arr2 – arr1 = [1, 7]

Given an array of citations, calculate the researcher’s h-index. https://leetcode.com/problems/h-index/

The Follow-up question was: https://leetcode.com/problems/h-index-ii/

Next follow-up question: What if we are getting a continuous stream of citations, and we need to calculate the h-index after each input?

Round 3 (DSA, Projects mentioned in the resume):  

A detailed discussion about the projects I have worked on and technologies and design patterns I have used.

Given an imbalanced BST, return the balanced BST.

Given the start and end times of the meetings, find out the maximum number of meetings one can attend. https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/

Puzzle: Given a 4-digit number ABCD, ABCD * 4 = DCBA (reversed number), find the values of A and D.

Round 4 (Java, Design):

Introduction and technical discussion about my recent project

OOPS questions

HashMap internal working

JVM architecture.

How is Java different than other object-oriented programming languages?

Detailed discussion on Garbage collector

You need to design a relational database; how will you design it? Which data structures will you use?

Find the top 3 horses puzzle.

Round 5 (Hiring Manager):

Quick introduction

If you are to design a garbage collector, how will you design it?

What is wrapper class and why do we need it?

What is type erasure and why do we need it?

Why do you want to leave the current organization?

Why GS?

He explained my role in the team

Hired!

The interview experience was smooth and it was very well arranged. On average, the whole procedure takes about 2-2.5 months to complete. 

Tips: 

Make sure you solve a few puzzles before you appear for the interview.

Be confident.

Related questions and answers

0 votes
asked Sep 19, 2019 in Interview Question by Robin
0 votes
asked Mar 29, 2020 in JAVA by amita rallin
0 votes
asked Dec 4, 2019 in JAVA by rajeshsharma
...