Problem database last updated: June 20, 2025

GGoldman Sachs logo

Goldman Sachs Coding Interview Questions

99 problems · 22 Easy, 66 Medium, 11 Hard · Ranked #13 of 458

Difficulty breakdown

22 Easy

22% · avg 23%

66 Medium

67% · avg 59%

11 Hard

11% · avg 18%

Top topics

array
62.6%
string
28.3%
hash-table
26.3%
dynamic-programming
22.2%
two-pointers
17.2%
math
17.2%

Interview profile

Based on 99 reported problems, Goldman Sachs interviews are in line with industry averages - 11% Hard vs 18% overall. The majority (67%) of questions are Medium difficulty, which is typical for companies that want to see solid fundamentals without excessive trick questions.

Compared to the industry average, Goldman Sachs puts unusual emphasis on quickselect (3% of problems, 2.9x the industry average), divide-and-conquer (6.1% of problems, 1.5x the industry average), prefix-sum (5.1% of problems, 1.5x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (62.6%), string (28.3%), hash-table (26.3%), dynamic-programming (22.2%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 99 problems

Trapping Rain Water

Solve

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

HardVery Likely
arraytwo-pointersdynamic-programming

Median of Two Sorted Arrays

Solve

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

HardVery Likely
arraybinary-searchdivide-and-conquer

First Unique Character in a String

Solve

Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

EasyVery Likely
hash-tablestringqueue

Fraction to Recurring Decimal

Solve

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

MediumVery Likely
hash-tablemathstring

Best Time to Buy and Sell Stock

Solve

You are given an array prices where prices[i] is the price of a given stock on the ith day.

EasyLikely
arraydynamic-programming

Number of Islands

Solve

Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

MediumLikely
arraydepth-first-searchbreadth-first-search

Minimum Path Sum

Solve

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

MediumLikely
arraydynamic-programmingmatrix

String Compression

Solve

Given an array of characters chars, compress it using the following algorithm:

MediumLikely
two-pointersstring

LRU Cache

Solve

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

MediumLikely
hash-tablelinked-listdesign

Two Sum

Solve

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.

EasyLikely
arrayhash-map

Group Anagrams

Solve

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

MediumLikely
arrayhash-tablestring

Container With Most Water

Solve

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

MediumLikely
arraytwo-pointersgreedy

Find Minimum in Rotated Sorted Array

Solve

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

MediumLikely
arraybinary-search

Decode Ways

Solve

You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping:

MediumLikely
stringdynamic-programming

Longest Substring Without Repeating Characters

Solve

Given a string s, find the length of the longest substring without duplicate characters.

MediumLikely
hash-tablestringsliding-window

Search in Rotated Sorted Array

Solve

There is an integer array nums sorted in ascending order (with distinct values).

MediumLikely
arraybinary-search

Minimize the Maximum of Two Arrays

Solve

We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:

MediumLikely
mathbinary-searchnumber-theory

Best Time to Buy and Sell Stock II

Solve

You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

MediumLikely
arraydynamic-programminggreedy

Kth Largest Element in an Array

Solve

Given an integer array nums and an integer k, return the kth largest element in the array.

MediumLikely
arraydivide-and-conquersorting

Valid Arrangement of Pairs

Solve

You are given a 0-indexed 2D integer array pairs where pairs[i] = [starti, endi]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.len...

HardLikely
arraydepth-first-searchgraph

Maximum Subarray

Solve

Given an integer array nums, find the subarray with the largest sum, and return its sum.

MediumSometimes
arraydivide-and-conquerdynamic-programming

Construct Smallest Number From DI String

Solve

You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.

MediumSometimes
stringbacktrackingstack

Power of Three

Solve

Given an integer n, return true if it is a power of three. Otherwise, return false.

EasySometimes
mathrecursion

Longest Increasing Subsequence

Solve

Given an integer array nums, return the length of the longest strictly increasing subsequence.

MediumSometimes
arraybinary-searchdynamic-programming

Longest Palindromic Substring

Solve

Given a string s, return the longest palindromic substring in s.

MediumSometimes
two-pointersstringdynamic-programming

Merge Intervals

Solve

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cove...

MediumSometimes
arraysorting

Valid Parentheses

Solve

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

EasySometimes
stringstack

Minimum Cost Homecoming of a Robot in a Grid

Solve

There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos =...

MediumSometimes
arraygreedy

Jump Game

Solve

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length...

MediumSometimes
arraydynamic-programminggreedy

Count Palindromic Subsequences

Solve

Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.

HardSometimes
stringdynamic-programming

Range Product Queries of Powers

Solve

Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in no...

MediumSometimes
arraybit-manipulationprefix-sum

Successful Pairs of Spells and Potions

Solve

You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potio...

MediumSometimes
arraytwo-pointersbinary-search

Sliding Window Maximum

Solve

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see...

HardSometimes
arrayqueuesliding-window

Keep Multiplying Found Values by Two

Solve

You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.

EasySometimes
arrayhash-tablesorting

Determine if Two Events Have Conflict

Solve

You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:

EasySometimes
arraystring

Count Number of Texts

Solve

Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.

MediumSometimes
hash-tablemathstring

Find All Good Indices

Solve

You are given a 0-indexed integer array nums of size n and a positive integer k.

MediumSometimes
arraydynamic-programmingprefix-sum

String to Integer (atoi)

Solve

Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.

MediumSometimes
string

Search a 2D Matrix

Solve

You are given an m x n integer matrix matrix with the following two properties:

MediumSometimes
arraybinary-searchmatrix

Product of Array Except Self

Solve

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

MediumSometimes
arrayprefix-sum

House Robber

Solve

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from rob...

MediumSometimes
arraydynamic-programming

Subarray Sum Equals K

Solve

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

MediumSometimes
arrayhash-tableprefix-sum

Pow(x, n)

Solve

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

MediumSometimes
mathrecursion

Next Permutation

Solve

A permutation of an array of integers is an arrangement of its members into a sequence or linear order.

MediumSometimes
arraytwo-pointers

Word Search

Solve

Given an m x n grid of characters board and a string word, return true if word exists in the grid.

MediumSometimes
arraystringbacktracking

Linked List Cycle

Solve

Given head, the head of a linked list, determine if the linked list has a cycle in it.

EasySometimes
hash-tablelinked-listtwo-pointers

Pascal's Triangle

Solve

Given an integer numRows, return the first numRows of Pascal's triangle.

EasySometimes
arraydynamic-programming

Sqrt(x)

Solve

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.

EasySometimes
mathbinary-search

Minimum Size Subarray Sum

Solve

Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If...

MediumSometimes
arraybinary-searchsliding-window

Missing Number

Solve

Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

EasySometimes
arrayhash-tablemath

Find Peak Element

Solve

A peak element is an element that is strictly greater than its neighbors.

MediumSometimes
arraybinary-search

Insert Delete GetRandom O(1)

Solve

Implement the RandomizedSet class:

MediumSometimes
arrayhash-tablemath

Climbing Stairs

Solve

You are climbing a staircase. It takes n steps to reach the top.

EasySometimes
mathdynamic-programmingmemoization

Minimum Number of Arrows to Burst Balloons

Solve

There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i]...

MediumSometimes
arraygreedysorting

Top K Frequent Elements

Solve

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

MediumSometimes
arrayhash-tabledivide-and-conquer

Maximum Product Subarray

Solve

Given an integer array nums, find a subarray that has the largest product, and return the product.

MediumSometimes
arraydynamic-programming

Gas Station

Solve

There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

MediumSometimes
arraygreedy

Count Number of Pairs With Absolute Difference K

Solve

Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.

EasySometimes
arrayhash-tablecounting

First Missing Positive

Solve

Given an unsorted integer array nums. Return the smallest positive integer that is not present in nums.

HardSometimes
arrayhash-table

Merge Two Sorted Lists

Solve

You are given the heads of two sorted linked lists list1 and list2.

EasySometimes
linked-listrecursion

Set Matrix Zeroes

Solve

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.

MediumSometimes
arrayhash-tablematrix

N-Queens

Solve

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

HardSometimes
arraybacktracking

Decode String

Solve

Given an encoded string, return its decoded string.

MediumSometimes
stringstackrecursion

Find Median from Data Stream

Solve

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two midd...

HardSometimes
two-pointersdesignsorting

Maximal Square

Solve

Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

MediumSometimes
arraydynamic-programmingmatrix

Next Greater Element I

Solve

The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.

EasySometimes
arrayhash-tablestack

Best Time to Buy and Sell Stock IV

Solve

You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.

HardSometimes
arraydynamic-programming

Candy

Solve

There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.

HardSometimes
arraygreedy

The Skyline Problem

Solve

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of...

HardSometimes
arraydivide-and-conquerbinary-indexed-tree

Add Two Numbers

Solve

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a sing...

MediumSometimes
linked-listmathrecursion

Letter Combinations of a Phone Number

Solve

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

MediumSometimes
hash-tablestringbacktracking

Roman to Integer

Solve

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

EasySometimes
hash-tablemathstring

Spiral Matrix

Solve

Given an m x n matrix, return all elements of the matrix in spiral order.

MediumSometimes
arraymatrixsimulation

Maximum XOR of Two Numbers in an Array

Solve

Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

MediumSometimes
arrayhash-tablebit-manipulation

Pascal's Triangle II

Solve

Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

EasySometimes
arraydynamic-programming

Rotate Array

Solve

Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.

MediumSometimes
arraymathtwo-pointers

Find the Duplicate Number

Solve

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

MediumSometimes
arraytwo-pointersbinary-search

Reorder List

Solve

You are given the head of a singly linked-list. The list can be represented as:

MediumSometimes
linked-listtwo-pointersstack

Permutations

Solve

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

MediumSometimes
arraybacktracking

Next Greater Element III

Solve

Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such pos...

MediumSometimes
mathtwo-pointersstring

Integer to Roman

Solve

Seven different symbols represent Roman numerals with the following values:

MediumSometimes
hash-tablemathstring

Amount of Time for Binary Tree to Be Infected

Solve

You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.

MediumSometimes
hash-tabletreedepth-first-search

Permutation in String

Solve

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

MediumSometimes
hash-tabletwo-pointersstring

Intersection of Two Linked Lists

Solve

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at al...

EasySometimes
hash-tablelinked-listtwo-pointers

Fraction Addition and Subtraction

Solve

Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.

MediumSometimes
mathstringsimulation

3Sum

Solve

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

MediumSometimes
arraytwo-pointerssorting

Valid Anagram

Solve

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

EasySometimes
hash-tablestringsorting

Rotate Image

Solve

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

MediumSometimes
arraymathmatrix

Reverse String

Solve

Write a function that reverses a string. The input string is given as an array of characters s.

EasySometimes
two-pointersstring

Largest Number

Solve

Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

MediumSometimes
arraystringgreedy

Remove Duplicate Letters

Solve

Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical or...

MediumRare
stringstackgreedy

Jump Game II

Solve

You are given a 0-indexed array of integers nums of length n. You are initially positioned at index 0.

MediumRare
arraydynamic-programminggreedy

Query Kth Smallest Trimmed Number

Solve

You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits.

MediumRare
arraystringdivide-and-conquer

Zigzag Conversion

Solve

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better...

MediumRare
string

Valid Sudoku

Solve

Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

MediumRare
arrayhash-tablematrix

Merge Sorted Array

Solve

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and num...

EasyRare
arraytwo-pointerssorting

Interleaving String

Solve

Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

MediumRare
stringdynamic-programming

Unique Paths

Solve

There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner...

MediumRare
mathdynamic-programmingcombinatorics

Contains Duplicate II

Solve

Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <=...

EasyRare
arrayhash-tablesliding-window

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent Goldman Sachs interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your Goldman Sachs coding interview

Goldman Sachs interviews focus heavily on array, string, hash-table problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. Goldman Sachs interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does Goldman Sachs ask in interviews?add

Goldman Sachs has been reported to ask 99 distinct coding problems. The most common topics are array, string, hash-table. 22 are Easy difficulty, 66 are Medium, and 11 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are Goldman Sachs coding interviews?add

Based on 99 reported problems, Goldman Sachs interviews are in line with industry averages - 11% Hard vs 18% overall. 67% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a Goldman Sachs coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, string, hash-table. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your Goldman Sachs interview?

Simulate a real Goldman Sachs coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a Goldman Sachs interview with AIarrow_forward