Goldman Sachs Interview Questions
0of 0 votesA List PARENTLIST which contains primitive type and List L, this List L further can have primitve type and List L and so on. Given a Root node calculate how many List it have
0of 0 votesGiven a huge file, design a data structure to output all possible anagrams of a particular word.
For Eg the file contains: "POT, OPT, TOP"
If I query for POT, I should get back all possible anagrams contained in the file.
--
0of 0 votesWrite a program to reverse the sequence of words in a sentence.
For Eg:
String str = "Today is Wednesday";
Output:
String str2 = "Wednesday is Today"
0of 0 voteswhich of the following is true for static member of the class?
a) internal linkage
b) external linkage
0of 0 votes#include<iostream>
#include<exception>
int main()
{
try
{
cout << "sum";
throw 3;
}
catch(...)
{
cout<< "dot";
}
catch(int a)
{
cout << a;
}
catch(exception e)
{
cout << "exception";
}
return 0;
}
what will be the output of the above program?
0of 2 votesFor the written test please prepare the following topics throughly :
a) virtual function
b) operator overloading
c) namespace
d) template
For interview, please prepare the container throughly with the implementation of list,map etc.
0of 2 votesclass a{
public:
int var1;
a(int var)
{
var1 = var;
}
};
class b: public a
{
public:
int var2;
b(int d) : var2( d++) , a(var2++)
{
}
};
int main
{
b obj1(5);
}
What will be the value of the variable 'var1' in class A?
a) 6
b)7
c) 5
d) undefined
0of 0 votesclass a{ public: int a; virtual void sum() { printf("sum"); } }; class b : public a { public: int b; virtual void sum() { printf("sum of class b"); } }; void main() { b aptr; a *bptr; bptr = &aptr; bptr->sum(); }Output of the above program?
0of 0 votesWhy the size of the empty class is one?
What are the default functions in an empty class.
does the size of empty class depend upon the compiler or hardware(32 bit or 64 bit)?
0of 0 votesAccording to the story, four prisoners are arrested for a crime, but the jail is full and the jailer has nowhere to put them. He eventually comes up with the solution of giving them a puzzle so if they succeed they can go free but if they fail they are executed.
The jailer puts three of the men sitting in a line. The fourth man is put behind a screen (or in a separate room). He gives all four men party hats (as in diagram). The jailer explains that there are two red and two blue hats; that each prisoner is wearing one of the hats; and that each of the prisoners is only to see the hats in front of them but not on themselves or behind. The fourth man behind the screen can't see or be seen by any other prisoner. No communication between the prisoners is allowed.
If any prisoner can figure out and say to the jailer what colour hat he has on his head all four prisoners go free. If any prisoner suggests an incorrect answer, all four prisoners are executed. The puzzle is to find how the prisoners can escape, regardless of how the jailer distributes the hats?
0of 0 votesPuzzle : There will be two sticks, if you burn each sticks from one side both will burn for an hour. You don't have any watch or stop watch, How you will measure 1 n half our and 45 min?
0of 0 votesFind wether there is a loop in a given liked list or no?
I solved it using two pointers. But they were not satisfied as I knew this solution before. They wanted me to solve using Single pointer.
0of 0 votesPrint 'n' elements of fibonacci series.
public int fibonacci(int n) { if ((n == 1) || (n==2)) { System.out.print("\t" + 1); return 1; } int temp = fibonacci (n-1) + fibonacci (n-2); System.out.println("\t" + temp); return temp;
0of 0 votesYou have gine n points with x and y cordinates (2 D), and you have to print how many of them are capable of forming a square and for each square print the points that are forming the square.
0of 0 votesSuppose u have a square matrix of 0s and 1s only ... find the longest path of 1s available in the matrix and return that .. you can only move right and down ... For e.g.
0 0 0 1 1
1 1 1 0 1
0 1 1 1 0
0 0 1 0 0
1 1 1 1 1
0of 0 votesDesign a data structure for LRU where replacement can take up to O(log n ) time, searching take O(log n) time, inserting will also take only O(log n) time(Big question, I was given some time(around 5 to 10 minute) to think) ?
0of 0 votesWhat is virtual memory, how operating system uses it ?
0of 0 votesHow can we reduce search time in linked list(reduce time complexity to O(log n), it is not given but I gave my answer with O(log n) complexity) ?
0of 0 votesDraw a simple model of a Program Control Block ?, Now write a simple code and show all the sections in the code (means when this code will run then which section of the code go where in PCB) ?
0of 0 votesPrint a binary tree without using recursion(inorder print) ?
0of 0 votesHow can I give new implementation to methods in String.
For example: I need to give new implementation to concat method, which concats two string and convert to uppercase.
I answered that, i create new custom class and create a method concat and implement it as the way interviewer want, but he asked that he want to do for all the methods in String, so writing new implementation for a methods is not a feasible solution.
0of 0 votesFor a given array size is know but elements using index is not accessible. 2 given functions are below:
1. getIndexOfNthLargest(int n) // returns the index of nth largest number. Like for n=1 the index of largest element will be returned, for n=2 the index of 2nd largest number will be returned.
2. reverseArray(int i) // reverse the elements of the array from index 0 to i
How to sort the array in place?
0of 0 votesThere is a stream of integers coming in. And you have to store top n elements. What data structures you would use?
1, The solution should be efficient such that n can be millions of integers.
2, Should be able to display integers in descending order. Sorting should not be done whenever requested.
3, Insert, Delete should be as optimal as possible.
0of 0 votesyou have array of characters with some spaces.. best way to take out only words..
input ==> a,a,b, , , c, , ,d,e
output ==> aabcde -- all spaces are removed..
best way to do?
-1of 1 voteWhat is the main use of interface ? Provide a real time example that shows it
0of 0 votesWhat is the importance of overriding in java ? Give any real life example . How is it increasing the code reusability and robustness .? Cant we create new function instead of override ? What difference will it make ?
0of 0 votesfind a^b using optimal algorithm.... [ no use of inbuilt functions?
0of 0 votesHow to find consecutive elements such that they have maximum sum ??
-2 4 2 3 -12 5 9 -3 4
=> Max SUM = 15
index i =5 to 8
0of 0 votesHow to find 4 largest elements of an given array of length n. Best possible option ??
0of 0 votesWhat is the next number in the series
2,4,8,16,24...