# Goldman Sachs Interview Experience (1.8 Years of Experience )

I was contacted by HR on LinkedIn

**Round 1(Online Coding Round): Hackerrank platform 1 hour 30 min**

- 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 “wwwwaaadexxxxxx”, then the function should return “w4a3d1e1x6” Expected Time Complexity: O(n)

- Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the number of possible decoding’s of the given digit sequence.
Input: digits[] = "121" Output: 3 The possible decoding's are "ABA", "AU", "LA" Input: digits[] = "1234" Output: 3 The possible decoding's are "ABCD", "LCD", "AWD" Expected Time Complexity: O(n)

**Round 2(F2F Coding Round): CoderPad with Goldman Sachs Developer**

- Given an array of strings strings, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Input: strs = ["eat","tea","tan","ate", "nat","bat"] Output: [["bat"],["nat","tan"], ["ate","eat","tea"]] Expected Time Complexity: O(n)

- Given a file containing data of student name and marks scored by him/her in 3 subjects. The task is to find the list of students having the maximum average score.
If more than one student has the maximum average score, print them as per the order in the file.

Input: file[] = {“Shrikanth”, “20”, “30”, “10”, “Ram”, “100”, “50”, “10”} Output: Ram 53

Average scores of Shrikanth, Ram are 20 and 53 respectively. So Ram has the maximum average score of 53.

Expected Time Complexity: O(n)

**Round 3(F2F Coding Round on Zoom): CoderPad with two Goldman Sachs Developers**

- Given a linked list, write a function to reverse every k nodes (where k is an input to the function).
Input: 1->2->3->4->5->6->7->8->NULL, K = 3 Output: 3->2->1->6->5->4->8->7->NULL Expected Time Complexity: O(n) Auxiliary Space: O(n/k).

- Given a Binary Search Tree (BST) and a positive integer k, find the k’th largest element in the Binary Search Tree.
- Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. All these operations of SpecialStack must be O(1). To implement SpecialStack, you should only use standard Stack data structure and no other data structure like arrays, list, .. etc.
Example: Consider the following SpecialStack 16 --> TOP 15 29 19 18 When getMin() is called it should return 15,

**Round 4(F2F Coding Round on Zoom): CoderPad with two Goldman Sachs Developers**

- Given an unsorted array arr[0..n-1] of size n, find the minimum length subarray arr[s..e] such that sorting this subarray makes the whole array sorted.
Example: If the input array is [10, 12, 20, 30, 25, 40, 32, 31, 35, 50, 60], your program should be able to find that the subarray lies between indexes 3 and 8.

- Given a binary array, in which, moving an element from index i to index j requires abs(i – j) cost. The task is to find the cost to move all 1s to each index of the given array.
Input: arr[] = {0, 1, 0, 1} Output: 4 2 2 2

**Explanation:**Moving elements from index 1, index 3 to index 0 requires abs(0 – 1) + abs(0 – 3) = 4.

Moving elements from index 1, index 3 to index 1 requires abs(1 – 1) + abs(1 – 3) = 2.

Moving elements from index 1, index 2 to index 2 requires abs(2 – 1) + abs(2 – 3) = 2.

Moving elements from index 1, index 2 to index 3 requires abs(3 – 1) + abs(3 – 3) = 2.

Therefore, the required output is 4 2 2 2.

**Round 5(F2F Coding Round on Zoom): CoderPad with two Goldman Sachs Developers**

- Problem of placing N chess queens on an N×N chessboard so that no two queens attack each other.
The expected output is a binary matrix which has 1s for the blocks where queens are placed.

For example, following is the output matrix for above 4 queen solution.

{ 0, 1, 0, 0} { 0, 0, 0, 1} { 1, 0, 0, 0} { 0, 0, 1, 0}

Solution: Use Recursion and Backtracking

- Implement a SnapshotArray that supports the following interface:
SnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0.

void set(index, val) sets the element at the given index to be equal to val.

int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.

int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id

Solution: Use the 2D Array of class Node , the 1D is used to store the indices and 2D is used to store the snap shots. For each index to get the value at particular snap id , we can use binary search as the snap array in each index will be sorted and Complexity of get Operation reduces to log(N)

**Round 6(F2F Coding Round on Zoom): CoderPad with two Goldman Sachs Developers**

- https://www.hackerrank.com/challenges/connected-cell-in-a-grid/problem

**Round 7(F2F Coding Round on Zoom): CoderPad with two Goldman Sachs Developers**

- Given an array of random numbers, Push all the zero’s of a given array to the end of the array. For example, if the given arrays is {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0}, it should be changed to {1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0}. The order of all other elements should be same.
Expected time complexity is O(n) and extra space is O(1).

- Some string-related basics and Strings in java and Python.

**Round 8(F2F Round on Zoom): CoderPad with two Goldman Sachs Developers**

- Few Questions on my recent projects, technologies I have worked on, and Cache Evacuation policies.
- Introduction to Customer wealth Management (CWM Goldman Sachs) Team, the products, and the Tech stacks Goldman’s uses.

After these rounds Finally I got a mail from HR for compensation discussion.