- 0
Notifications Mark All Read
- Login
- Get Prime
Goldman Sachs Technical Interview Questions
Goldman Sachs Technical Interview Questions and Answers 2023
You may find the most often asked technical interview questions by Goldman Sachs on this page.
Page Highlights:
- Goldman Sachs
- Test Pattern
Top 20 Goldman Sachs Technical Interview Questions
Question 1: What is a deadlock?
Answer:
When two computer programs that are using the same resource effectively block each other from using it, the programs become dysfunctional. This circumstance is known as a deadlock.
Question 2: Write a program to print nonrepeating elements in an array.
#include <stdio.h> // Main function to run the program int main() { int arr[] = {21, 30, 10, 2, 10, 20, 30, 11}; int n = sizeof(arr)/sizeof(arr[0]); int visited[n]; for(int i=0; i<n; i++){ if(visited[i]==0){ int count = 1; for(int j=i+1; j<n; j++){ if(arr[i]==arr[j]){ count++; visited[j]=1; } } if(count==1) printf("%d ",arr[i]); } } return 0; }
Question 3: What is diamond's problem in C++?
Answer:
When two parent classes share a grandparent class and both parent classes are inherited by a single child class, an issue known as the Diamond Problem occurs in multiple inheritances.
Questions 4: Write a program to find the Equilibrium index of an array.
import java.util.*; public class PrepInsta { static int equilibrium_index(int arr[], int n) { int sum = 0; int leftsum = 0; for (int i = 0; i < n; ++i) sum += array[i]; for (int i = 0; i < n; ++i) { sum -= array[i]; if (leftsum == sum) return i; leftsum += array[i]; } return -1; } public static void main(String[] args) { int arr[] = { 1,2,3,4,5,1,3,2,4 }; int arr_size = arr.length; System.out.print("Equilibrium Index : "); System.out.println(equilibrium_index(arr, arr_size)); } }
Question 5: What is the final keyword in Java?
Answer:
The final keyword is a non-access modifier that prevents modification of classes, attributes, and methods.
Question 6: What are processes and threads in the context of OS?
Answer:
Process: The programs that are dispatched from the ready state and scheduled for execution in the CPU are basically called processes.
Thread: A thread is a segment of a process, which implies that a process can have several threads, and these multiple threads are held within a process. A thread can be in one of three states: running, ready, and blocked.
Question 7: Write a program to implement a queue using not more than 2 stacks.
#include <stdio.h> #include<stdlib.h> #define N 100 // size for arrays representing stack1 and stack2 int stack1[N], stack2[N]; // array representing stacks of size N int top_stack1 = -1; // top for stack1 int top_stack2 = -1; // top for stack2 int count = 0; // For keeping the count of element present in queue void push_stack1 (int data) { if (top_stack1 == N - 1){ printf ("Stack1 is overflow"); return; } else{ top_stack1++; stack1[top_stack1] = data; } return; } void push_stack2 (int data) { if (top_stack2 == N - 1){ printf ("Stack2 is overflow"); return; } else { top_stack2++; stack2[top_stack2] = data; } return; } int pop_stack1 () { if (top_stack1 == -1){ printf ("Stack1 is underflow\n"); return -1; } return stack1[top_stack1--]; } int pop_stack2 () { if (top_stack2 == -1) { printf ("Stack2 is underflow\n"); return -1; } return stack2[top_stack2--]; } void enqueue (int data) { push_stack1 (data); count++; } void dequeue () { if (top_stack1 == -1 && top_stack2 == -1) printf ("Queue is empty\n"); else { for (int i = 0; i < count; i++){ int temp = pop_stack1 (); push_stack2 (temp); } int x = pop_stack2 (); printf ("Dequeued element is %d\n", x); count--; for (int i = 0; i < count; i++){ int temp = pop_stack2 (); push_stack1 (temp); } } } void display () { if (top_stack1 == -1) { printf ("Queue is empty \n"); return; } for (int i = 0; i < top_stack1; i++) printf ("%d ", stack1[i]); printf ("\n"); } void top () { printf ("Top element of queue is %d ", stack1[0]); } int main () { enqueue (3); enqueue (45); enqueue (-1); display(); dequeue (); enqueue (-1); display (); return 0; }
Question 8: Write a program for the Relational Operator Overloading
#include <iostream> using namespace std; class Student{ int feet = 0; //can be b/w 0 & infinity int inches = 0; // can be b/w 0 & 12 public: void getHeight(int f, int i){ feet = f; inches = i; } // const and & added check explanation above(Before code) why bool operator > (const Student& s2) { if(feet > s2.feet) return true; else if(feet == s2.feet && inches > s2.inches) return true; return false; } }; int main() { Student s1,s2; s1.getHeight(5,10); s2.getHeight(6,1); if(s1 > s2) cout << "Student 1 is taller" << endl; else if(s2 > s1) cout << "Student 2 is taller" << endl; else cout << "Both have equal height" << endl; return 0; }
Questions 9: What is hashCode() in Java?
Answer:
In Java, a hashCode function returns the hashcode value of an object when called. As a result of the hashing process, it returns an integer or a value of 4 bytes. Hashing is the process of providing a unique value to an object or property using an algorithm to allow for quicker access.
Question 10: Write a program to toggle each character in a string.
#include <stdio.h> #include <string.h> // Make sure that have knowledge about ASCII // if not please check - https://prepinsta.com/ascii-table/ int main() { //Initializing variable. char str[100]; int i; //Accepting input. printf("\n Please Enter any String: "); gets(str); //Initializing for loop. for (i = 0; str[i]!='\0'; i++) { //Toggling characters. if(str[i] >= 'A' && str[i] <= 'Z') str[i] = str[i] + 32; else if(str[i] >= 'a' && str[i] <= 'z') str[i] = str[i] - 32; } printf("\n Toglled string: %s", str); return 0; }
Question 11: What is data structure?
Answer:
A data structure is a method of arranging data that takes into account both the things contained and their connections with one another. Advanced understanding of the relationships between data elements enables the creation of effective data manipulation algorithms.
Question 12: Write a program to Find kth max and min elements in the array.
def findkmax(k, array): # sort the array in descending order array.sort(reverse=True) # Since indexing start from 0, hence if user want first number, that means index=0 print("K th maximum element is: ", array[k - 1]) def findkmin(k, array): # sort the array in ascending order array.sort() # Since indexing start from 0, hence if user want first number, that means index=0 print("K th minimum element is: ", array[k - 1]) array = [1, 7, 6, 8, 9, 2, 4, 5, 3, 0] k = 2 # call function findkmax findkmax(k, array) # call function findkmin findkmin(k, array)
Question 13: Classify the Hashing Functions based on the various approaches for locating the key value.
Answer:
- Direct method,
- Subtraction method,
- Modulo-
- Division method,
- Digit-
- Extraction method,
- Mid-Square method,
- Folding method,
- Pseudo-random method.
Question 14: What is Domain-Key Normal Form?
Answer:
A relation is said to be in DKNF if all dependencies and constraints that must hold on the constraint can be enforced by only imposing the domain constraint and key control on the relation.
Question 15: Write a program to find the Factorial of a Large Number.
Question 16: What is indexing and what are the different kinds of indexing?
Answer:
Indexing is a method for finding out how quickly certain data can be located. The different types of Indexing are:
- Binary search style indexing
- B-Tree indexing
- Inverted list indexing
- Memory resident table
- Table indexing
Question 17: What are local and global page replacements?
Answer:
Local replacement refers to bringing an incoming page exclusively into the appropriate process address space.
The global replacement policy enables the replacement of any page frame from any process. Only the variable partitions model may use the latter.
Question 18: What is a node?
Answer:
A network can be made up of two or more computers that are physically linked together, such as through an optical fibre or coaxial cable. These physical connections are known as Links, and the computers they link are known as Nodes.
Question 19: Write a program to find the Last non-zero digit in factorial.
#include <stdio.h> //Recursive function to calculate the factorial int fact(int n){ if(n <= 1) //Base Condition return 1; return n*fact(n-1); } //Driver Code int main(){ int n=5; int factorial = fact(n); while(factorial%10==0) { factorial /= 10; } printf("%d",factorial%10); }
Question 20: Write a program to remove all adjacent duplicate characters recursively.
def removeUtil(string, last_removed): if len(string) == 0 or len(string) == 1: return string if string[0] == string[1]: last_removed = ord(string[0]) while len(string) > 1 and string[0] == string[1]: string = string[1:] string = string[1:] return removeUtil(string, last_removed) rem_str = removeUtil(string[1:], last_removed) if len(rem_str) != 0 and rem_str[0] == string[0]: last_removed = ord(string[0]) return rem_str[1:] if len(rem_str) == 0 and last_removed == ord(string[0]): return rem_str return [string[0]] + rem_str def remove(string): last_removed = 0 return "".join(removeUtil(list(string), last_removed)) string1 = "acaabbbceddd" print(remove(string1))
Login/Signup to comment