I had 2 years of experience when I got a call from Goldman about hiring going on for a certain team. There were 6 rounds in total (2 online + 4 onsite).

**Round 1:** Hackerrank

There were 2 questions which you can attempt at home. Since the preferred language was Java/Python, I used Java to solve them. I do not remember the questions exactly. I somewhat remember the second question. The question was:

- Merge adjacent elements of an array based on certain conditions until that condition was getting satisfied. Then, the output was to print the final set of elements in the array.

I got a call from HR after a week to finalize the date for coderpad round. HR asked me to confirm if I was proficient in Java/Python or not. I mentioned that I know Core Java but I would like to use C++ for coding as it is easy to code using it. She told me to discuss this with the interviewer. The finalized date was one week after the call.

**Round 2:** Coderpad

I could see that C++ was available for coding. But Java was finalized as the language of coding after discussion with the interviewer.

- Given two fractions which are represented as an array of two elements (numerator and denominator), the task to find the reduced fraction which is the sum of two fractions.
- Given two sorted arrays, find the median of them.

This first question was an easy mathematical problem which will also involve GCD. I discussed the approach and coded it in 5-10 minutes. I missed the corner case of negative numbers. I put validation for the same and then moved on to the next question.

This second one is a standard problem but I was not aware of the fastest approach. I could think of an approach where I was making sure that elements are shuffled in a way that both of them are sorted and the last element of the left array is less than or equal to the first element of the right array. I discussed the approach which he understood and then I started to code. I had almost finished the coding when time got over. He said that code could be optimized but he understood my approach.

I could then think of the O(n) approach which involves merging of two sorted arrays where we do not merge actually and just have to keep count of the middle element. There is another approach which is O(logn) and involves comparing the median of two sorted arrays. The date of onsite round was kept after two weeks.

**Round 3** Onsite

- The question was modification of this Find the first circular tour that visits all petrol pumps. The additional condition here was to make sure that petrol utilization was minimum.

It was difficult for me to think about the optimal approach in the beginning. Then I suggested the brute force approach where at any point we can choose to pick or not pick the pump. We can choose the best one out of it. Then after some discussion, I got a hint after which I could think of an approach involving heap (priority queue). I was asked to code this approach. The question was then modified again to add a condition that at any pump, we cannot pick more than x amount of petrol. I did some conditional change to my approach but could not think of any other optimization.

The second interviewer checked my resume and he wanted to ask some questions related to JS. I mentioned that I was not comfortable in the same and he could ask me JAVA. He said it was okay and he was done. But the first interviewer asked me questions related to HashMap, its implementation (load factor and other topics), worst case of get operation, implementation of heaps, etc.

**Round 4:** Onsite

- Given a set of pairs which represent a game between two teams in a tournament and corresponding winner of each pair, find the result of a query where we give two teams and we have to find a winner between them (assuming two teams do not play more than once).
- Given a string that can contain special characters, the task was to find if string formed using characters (ignoring special ones) is a palindrome.

I approached this problem using a directed graph. We can build a directed graph using the tournament data. If we can find a path between T1 to T2, T1 is the winner. If the same happens for T2 to T1, T2 is the winner. If no path is found, then data is inadequate.

The approach had to be optimized for the huge number of queries (10^5). I used a hashmap to store graph data (adjacency matrix/list) which would be optimal during query.

I wrote the code in 10 minutes. I missed one case in my code. I rechecked and then submitted it again. It is important to note that the code must be production-grade (bug-free). Even if we code fast, accuracy is an important concern. Take 5 extra minutes but think of all edge cases.

**Round 5:** Onsite

We need to design two methods – store and query. The task here is to make sure that we think of an approach to make these methods faster. We can do trade-offs (query can be given more importance than storage in this case – this was not specified explicitly).

I used hashmap and heap to solve the problem. The interviewer was satisfied with the approach.

The approach was to keep in mind that XOR of a number with itself is 0. If we do XOR of n with the given set, we will get x somewhere (y will be canceled) in the first list. Similarly, we will get x in the second list. Search for similarity of a number in two lists (assuming uniqueness) will give x. I could solve this problem in 5 minutes fortunately and the interviewer seemed satisfied.

**Round 6:** Onsite

One of the interviewers appeared to me as a manager. I was asked to explain my current work in layman terms. Then, there was one DS problem – Find a pair that has the sum closest of a given number X. I coded and explained my approach which involved two pointers.

The next question was related to DB (joins). I approached the problem but could not find a simplified query. I explained that this would be simple to solve in ABAP (language used in my current project). But they said it would not be of any use as they are not aware of the same.

The last question was a puzzle. Given 3 trains which start at the same time and place and we can transfer fuel from one train to another such that limit does not exceed given X (for all trains), find the maximum distance covered by any of the trains. I was able to think of approach after a hint. We can transfer fuel from one train to other after 1/3 interval. This can be generalized to 1/n for n trains. The resultant distance will be a harmonic progression. The interview ended with some general discussion.

HR informed me that my feedback was positive.