Goldman Sachs Placement Papers 2024
Access 2024 Goldman Sachs OA questions with solutions and exam pattern analysis.
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:
Goldman Sachs Placement Papers 2024
Access 2024 Goldman Sachs OA questions with solutions and exam pattern analysis.
Goldman Sachs Placement Papers 2025
Practice latest 2025 Goldman Sachs OA questions with updated patterns.
Complete Goldman Sachs guide
Access complete Goldman Sachs placement papers guide with eligibility, process, and preparation strategy.
Goldman Sachs Online Assessment Breakdown:
| Section | Questions | Time | Difficulty | Focus Areas |
|---|---|---|---|---|
| Coding Test | 2-3 | 60-90 min | Medium | Arrays, strings, DP, math, optimization |
Languages Allowed: C, C++, Java, Python
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_profitTime Complexity: O(n) | Space Complexity: O(1)
Problem: Find indices of two numbers that add up to target.
Example:
Input: nums = [2, 7, 11, 15], target = 9Output: [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)
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_farTime Complexity: O(n) | Space Complexity: O(1)
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_lenTime Complexity: O(n) | Space Complexity: O(min(m,n))
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)
Problem: Find GCD and LCM of two numbers.
Example:
Input: a = 12, b = 18Output: GCD = 6, LCM = 36Solution (Java):
public int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
public int lcm(int a, int b) { return (a * b) / gcd(a, b);}Solution (Python):
def gcd(a, b): while b: a, b = b, a % b return a
def lcm(a, b): return (a * b) // gcd(a, b)Time Complexity: O(log(min(a,b))) | Space Complexity: O(1)
Problem: Count primes less than n using Sieve of Eratosthenes.
Example:
Input: n = 10Output: 4 (primes: 2, 3, 5, 7)Solution (Java):
public int countPrimes(int n) { if (n <= 2) return 0; boolean[] isPrime = new boolean[n]; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i < n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) { isPrime[j] = false; } } }
int count = 0; for (boolean prime : isPrime) { if (prime) count++; } return count;}Solution (Python):
def count_primes(n): if n <= 2: return 0 is_prime = [True] * n is_prime[0] = is_prime[1] = False
for i in range(2, int(n ** 0.5) + 1): if is_prime[i]: for j in range(i * i, n, i): is_prime[j] = False
return sum(is_prime)Time Complexity: O(n log log n) | Space Complexity: O(n)
Problem: Implement pow(x, n) - calculate x raised to power n.
Example:
Input: x = 2.0, n = 10Output: 1024.0Solution (Java):
public double myPow(double x, int n) { long N = n; if (N < 0) { x = 1 / x; N = -N; }
double result = 1; while (N > 0) { if (N % 2 == 1) { result *= x; } x *= x; N /= 2; } return result;}Solution (Python):
def my_pow(x, n): if n < 0: x = 1 / x n = -n
result = 1 while n > 0: if n % 2 == 1: result *= x x *= x n //= 2 return resultTime Complexity: O(log n) | Space Complexity: O(1)
Problem: Find integer square root without using sqrt function.
Example:
Input: x = 8Output: 2 (sqrt(8) = 2.828...)Solution (Java):
public int mySqrt(int x) { if (x < 2) return x; long left = 1, right = x / 2;
while (left <= right) { long mid = left + (right - left) / 2; long square = mid * mid;
if (square == x) return (int) mid; if (square < x) left = mid + 1; else right = mid - 1; } return (int) right;}Solution (Python):
def my_sqrt(x): if x < 2: return x left, right = 1, x // 2
while left <= right: mid = (left + right) // 2 if mid * mid == x: return mid if mid * mid < x: left = mid + 1 else: right = mid - 1 return rightTime Complexity: O(log n) | Space Complexity: O(1)
Problem: Count trailing zeroes in n!
Example:
Input: n = 25Output: 6 (25! = ...000000)Solution (Java):
public int trailingZeroes(int n) { int count = 0; while (n >= 5) { count += n / 5; n /= 5; } return count;}Solution (Python):
def trailing_zeroes(n): count = 0 while n >= 5: count += n // 5 n //= 5 return countTime Complexity: O(log n) | Space Complexity: O(1)
Problem: Count ways to climb n stairs (1 or 2 steps at a time).
Example:
Input: n = 4Output: 5 (ways: 1111, 112, 121, 211, 22)Solution (Java):
public int climbStairs(int n) { if (n <= 2) return n; int prev2 = 1, prev1 = 2; for (int i = 3; i <= n; i++) { int curr = prev1 + prev2; prev2 = prev1; prev1 = curr; } return prev1;}Solution (Python):
def climb_stairs(n): if n <= 2: return n prev2, prev1 = 1, 2 for i in range(3, n + 1): curr = prev1 + prev2 prev2, prev1 = prev1, curr return prev1Time Complexity: O(n) | Space Complexity: O(1)
Problem: Find minimum coins needed to make amount.
Example:
Input: coins = [1, 2, 5], amount = 11Output: 3 (5 + 5 + 1)Solution (Java):
public int coinChange(int[] coins, int amount) { int[] dp = new int[amount + 1]; Arrays.fill(dp, amount + 1); dp[0] = 0;
for (int i = 1; i <= amount; i++) { for (int coin : coins) { if (coin <= i) { dp[i] = Math.min(dp[i], dp[i - coin] + 1); } } } return dp[amount] > amount ? -1 : dp[amount];}Solution (Python):
def coin_change(coins, amount): dp = [float('inf')] * (amount + 1) dp[0] = 0
for i in range(1, amount + 1): for coin in coins: if coin <= i: dp[i] = min(dp[i], dp[i - coin] + 1)
return dp[amount] if dp[amount] != float('inf') else -1Time Complexity: O(amount × coins) | Space Complexity: O(amount)
Problem: Find length of longest increasing subsequence.
Example:
Input: [10,9,2,5,3,7,101,18]Output: 4 ([2,3,7,101])Solution (Java):
public int lengthOfLIS(int[] nums) { int[] tails = new int[nums.length]; int size = 0;
for (int num : nums) { int left = 0, right = size; while (left < right) { int mid = (left + right) / 2; if (tails[mid] < num) { left = mid + 1; } else { right = mid; } } tails[left] = num; if (left == size) size++; } return size;}Solution (Python):
import bisect
def length_of_lis(nums): tails = [] for num in nums: pos = bisect.bisect_left(tails, num) if pos == len(tails): tails.append(num) else: tails[pos] = num return len(tails)Time Complexity: O(n log n) | Space Complexity: O(n)
Problem: Maximum money that can be robbed (no adjacent houses).
Example:
Input: [2,7,9,3,1]Output: 12 (rob houses 0, 2, 4: 2+9+1)Solution (Java):
public int rob(int[] nums) { if (nums.length == 0) return 0; if (nums.length == 1) return nums[0];
int prev2 = 0, prev1 = 0; for (int num : nums) { int curr = Math.max(prev1, prev2 + num); prev2 = prev1; prev1 = curr; } return prev1;}Solution (Python):
def rob(nums): prev2 = prev1 = 0 for num in nums: curr = max(prev1, prev2 + num) prev2, prev1 = prev1, curr return prev1Time Complexity: O(n) | Space Complexity: O(1)
Problem: Find minimum operations to convert word1 to word2.
Example:
Input: word1 = "horse", word2 = "ros"Output: 3Solution (Java):
public int minDistance(String word1, String word2) { int m = word1.length(), n = word2.length(); int[][] dp = new int[m + 1][n + 1];
for (int i = 0; i <= m; i++) dp[i][0] = i; for (int j = 0; j <= n; j++) dp[0][j] = j;
for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (word1.charAt(i-1) == word2.charAt(j-1)) { dp[i][j] = dp[i-1][j-1]; } else { dp[i][j] = 1 + Math.min(dp[i-1][j-1], Math.min(dp[i-1][j], dp[i][j-1])); } } } return dp[m][n];}Time Complexity: O(m×n) | Space Complexity: O(m×n)
Problem: Return level order traversal of binary tree.
Solution (Java):
public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> result = new ArrayList<>(); if (root == null) return result;
Queue<TreeNode> queue = new LinkedList<>(); queue.offer(root);
while (!queue.isEmpty()) { int size = queue.size(); List<Integer> level = new ArrayList<>();
for (int i = 0; i < size; i++) { TreeNode node = queue.poll(); level.add(node.val); if (node.left != null) queue.offer(node.left); if (node.right != null) queue.offer(node.right); } result.add(level); } return result;}Time Complexity: O(n) | Space Complexity: O(n)
Problem: Find LCA of two nodes in binary tree.
Solution (Java):
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null || root == p || root == q) return root;
TreeNode left = lowestCommonAncestor(root.left, p, q); TreeNode right = lowestCommonAncestor(root.right, p, q);
if (left != null && right != null) return root; return left != null ? left : right;}Time Complexity: O(n) | Space Complexity: O(h)
Problem: Count islands in a 2D grid.
Solution (Java):
public int numIslands(char[][] grid) { int count = 0; for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { if (grid[i][j] == '1') { dfs(grid, i, j); count++; } } } return count;}
private void dfs(char[][] grid, int i, int j) { if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] == '0') return; grid[i][j] = '0'; dfs(grid, i+1, j); dfs(grid, i-1, j); dfs(grid, i, j+1); dfs(grid, i, j-1);}Time Complexity: O(m×n) | Space Complexity: O(m×n)
Master fundamentals
Focus on clean code
Time management
Finance-related problems
JP Morgan · Morgan Stanley · Deutsche Bank · Bank of America · Capital One · Wells Fargo