Goldman Sachs
10+ GM Agro & Beverages Interview Questions and Answers
Q1. Delete a Node from a Linked List
You are provided with a linked list of integers. Your task is to implement a function that deletes a node located at a specified position 'POS'.
Input:
The first line contains a...read more
Q2. Buy and Sell Stock Problem Statement
Imagine you are Harshad Mehta's friend, and you have been given the stock prices of a particular company for the next 'N' days. You can perform up to two buy-and-sell transa...read more
Q3. DFS Traversal Problem Statement
Given an undirected and disconnected graph G(V, E)
, where V
is the number of vertices and E
is the number of edges, the connections between vertices are provided in the 'GRAPH' m...read more
Q4. Matrix Word Search Problem
Explanation: You are given an 'M' x 'N' matrix of characters named CHARACTER_MATRIX
and a string WORD
. Your task is to identify and list all the occurrences of the string within the m...read more
Q5. Morse Code to English Problem Statement
You are provided with a string of morse code(s) of length N. Your task is to convert this morse code into the corresponding alphanumeric code consisting of lowercase Engl...read more
Q6. Transitive Closure of Directed Graph Problem Statement
Given a directed graph with 'V' vertices and 'E' edges, determine if a vertex i
is reachable from vertex j
for all pairs of vertices (i, j)
. A vertex j
is ...read more
Q8. randN function : which generates random number in [1,2,3..N] with equal probability. Given rand5, write a code for rand7 using rand5
Code for rand7 using rand5 function
Use rand5 twice to generate a number in [1,25] with equal probability
If the number is greater than 21, discard and try again
Otherwise, return (number mod 7) + 1
Q9. Print all nodes at a distance k from a given node in binary tree?
Print all nodes at a distance k from a given node in binary tree
Use Depth First Search (DFS) to traverse the tree
Maintain a variable to keep track of the distance from the given node
Print the nodes when the distance is equal to k
Q10. Puzzle: Using all(8,8,3,3) and only operators(*,/,-,+), make 24
Using 8,8,3,3 and only *, /, -, + operators, make 24.
Start with 8+8=16
Divide 3 by 3 to get 1
Multiply 16 by 1 to get 16
Add 8 to 16 to get 24
Q11. Write down function to select pivot element randomly in Quick Sort
Function to randomly select pivot element in Quick Sort
Generate a random index within the range of the array
Return the element at the randomly generated index as the pivot
Q12. How do you implement LRU cache?
LRU cache is implemented using a doubly linked list and a hash map.
Create a doubly linked list to keep track of the order of elements in the cache.
Create a hash map to store the key-value pairs of the cache.
When a new element is added, check if the cache is full. If it is, remove the least recently used element from the linked list and the hash map.
When an element is accessed, move it to the front of the linked list to mark it as the most recently used.
When an element is remo...read more
Q13. What is inheritance in java?
Inheritance in Java allows a class to inherit properties and behavior from another class.
Inheritance allows for code reusability and promotes a hierarchical relationship between classes.
Subclasses can access the methods and fields of their superclass.
Example: class Dog extends Animal {} - Dog inherits properties and behavior from Animal class.
Q14. Difference between OOP and POP
OOP focuses on objects and classes, while POP focuses on procedures and functions.
OOP emphasizes data encapsulation and inheritance
POP emphasizes sequential execution of procedures
Example of OOP: Java, C++
Example of POP: C, Pascal
More about working at Goldman Sachs
Interview Process at GM Agro & Beverages
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month