Skip to content

Goldman Sachs Coding Questions 2025 - DSA Problems & Solutions

Practice 25+ Goldman Sachs placement paper coding questions with detailed solutions. Access Goldman Sachs OA coding problems, DSA questions in Java, Python, C++ for Goldman Sachs placement 2025-2026.

Goldman Sachs Placement Paper Coding Questions - Complete Guide

Section titled “Goldman Sachs Placement Paper Coding Questions - Complete Guide”

Practice with 25+ Goldman Sachs placement paper coding questions covering DSA problems, algorithms, and system design concepts. These questions are representative of what you’ll encounter in Goldman Sachs online assessment and technical interviews.

What’s Included:

  • 25+ Coding Problems: Easy, Medium, and Hard level questions with solutions
  • Multiple Language Solutions: Java, Python, and C++ solutions
  • Time Complexity Analysis: Every solution includes complexity analysis
  • Goldman Sachs Focus Areas: Arrays, strings, trees, dynamic programming, math

Goldman Sachs Placement Papers 2024

Access 2024 Goldman Sachs OA questions with solutions and exam pattern analysis.


View 2024 Papers →

Goldman Sachs Placement Papers 2025

Practice latest 2025 Goldman Sachs OA questions with updated patterns.


View 2025 Papers →

Complete Goldman Sachs Guide

Access complete Goldman Sachs placement papers guide with eligibility, process, and preparation strategy.


View Complete Guide →

Goldman Sachs Online Assessment Breakdown:

SectionQuestionsTimeDifficultyFocus Areas
Coding Test2-360-90 minMediumArrays, strings, DP, math, optimization

Languages Allowed: C, C++, Java, Python

Best Time to Buy and Sell Stock

Problem: Find maximum profit from buying and selling stock once.

Example:

Input: [7,1,5,3,6,4]
Output: 5 (buy at 1, sell at 6)

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;
}

Solution (Python):

def max_profit(prices):
min_price = float('inf')
max_profit = 0
for price in prices:
min_price = min(min_price, price)
max_profit = max(max_profit, price - min_price)
return max_profit

Time Complexity: O(n) | Space Complexity: O(1)

Two Sum

Problem: Find indices of two numbers that add up to target.

Example:

Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]

Solution (Java):

public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[]{map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[]{};
}

Solution (Python):

def two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
if target - num in seen:
return [seen[target - num], i]
seen[num] = i
return []

Time Complexity: O(n) | Space Complexity: O(n)

Maximum Subarray (Kadane’s Algorithm)

Problem: Find contiguous subarray with largest sum.

Example:

Input: [-2,1,-3,4,-1,2,1,-5,4]
Output: 6 (subarray [4,-1,2,1])

Solution (Java):

public int maxSubArray(int[] nums) {
int maxSoFar = nums[0];
int maxEndingHere = nums[0];
for (int i = 1; i < nums.length; i++) {
maxEndingHere = Math.max(nums[i], maxEndingHere + nums[i]);
maxSoFar = Math.max(maxSoFar, maxEndingHere);
}
return maxSoFar;
}

Solution (Python):

def max_sub_array(nums):
max_so_far = max_ending_here = nums[0]
for num in nums[1:]:
max_ending_here = max(num, max_ending_here + num)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far

Time Complexity: O(n) | Space Complexity: O(1)

Longest Substring Without Repeating

Problem: Find length of longest substring without repeating characters.

Example:

Input: "abcabcbb"
Output: 3 (substring "abc")

Solution (Java):

public int lengthOfLongestSubstring(String s) {
Map<Character, Integer> seen = new HashMap<>();
int maxLen = 0, left = 0;
for (int right = 0; right < s.length(); right++) {
char c = s.charAt(right);
if (seen.containsKey(c) && seen.get(c) >= left) {
left = seen.get(c) + 1;
}
seen.put(c, right);
maxLen = Math.max(maxLen, right - left + 1);
}
return maxLen;
}

Solution (Python):

def length_of_longest_substring(s):
seen = {}
max_len = left = 0
for right, char in enumerate(s):
if char in seen and seen[char] >= left:
left = seen[char] + 1
seen[char] = right
max_len = max(max_len, right - left + 1)
return max_len

Time Complexity: O(n) | Space Complexity: O(min(m,n))

Product of Array Except Self

Problem: Return array where each element is product of all others (no division).

Example:

Input: [1,2,3,4]
Output: [24,12,8,6]

Solution (Java):

public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] result = new int[n];
result[0] = 1;
for (int i = 1; i < n; i++) {
result[i] = result[i-1] * nums[i-1];
}
int right = 1;
for (int i = n-1; i >= 0; i--) {
result[i] *= right;
right *= nums[i];
}
return result;
}

Time Complexity: O(n) | Space Complexity: O(1)

Master Fundamentals

  • Arrays, strings, hash maps
  • Mathematical operations
  • Dynamic programming
  • Tree/Graph traversals

Focus on Clean Code

  • Goldman values code quality
  • Write readable, efficient code
  • Handle edge cases
  • Comment where needed

Time Management

  • 25-30 minutes per problem
  • Read problem carefully
  • Test with examples
  • Optimize if time permits

Finance-Related Problems

  • Stock buy/sell problems
  • Interest calculations
  • Portfolio optimization
  • Risk assessment
Practice More Goldman Sachs Coding Questions →

Practice Goldman Sachs coding questions regularly! Focus on arrays, mathematical operations, and dynamic programming. Goldman Sachs values clean, efficient code.

Pro Tip: Goldman Sachs interviews also test financial domain knowledge. Understand basic financial concepts along with coding.

Last updated: February 2026