Skip to content

Goldman Sachs Coding Questions - DSA Problems & Solutions

Practice Goldman Sachs placement paper coding questions with detailed solutions. Access Goldman Sachs OA coding problems in Java, C++, Python.

This page contains Goldman Sachs coding questions from Goldman Sachs OA placement papers with detailed solutions.

Goldman Sachs OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 60 minutes
  • Languages: C, C++, Java, Python
Q1: Find the maximum profit from buying and selling stock.

Solution (Java):

public int maxProfit(int[] prices) {
int minPrice = Integer.MAX_VALUE;
int maxProfit = 0;
for (int price : prices) {
if (price < minPrice) {
minPrice = price;
} else if (price - minPrice > maxProfit) {
maxProfit = price - minPrice;
}
}
return maxProfit;
}

Time Complexity: O(n)


Practice Goldman Sachs coding questions regularly!