Goldman Sachs logo

Goldman Sachs Hard Interview Questions

5 hard-level practice questions for Goldman Sachs technical interviews

Goldman Sachs software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Parallel Task Scheduler


Category: Algorithm coding problem

Question You are given n tasks, each taking a certain number of hours to complete. Tasks may depend on other tasks - a task cannot start until...

Input: Number(s)
Output: Integer
Want to practise this one?
Create a free account to open the full question and practise Goldman Sachs questions with AI.
Sign up free
coding Hard graph #1

1. [AI Enabled Coding] Treasury Payment Release Engine


Scenario
Goldman Sachs Transaction Banking (TxB) supports corporate treasury and payment workflows. In this interview exercise, build a batch-release engine that prevents a payment from being released before its prerequisite funding transfers and enforces client and funding-account controls. Treasury operations needs deterministic decisions and an auditable explanation for every rejected payment; the policies below are synthetic interview requirements, not claims about Goldman Sachs's production policies.
Part 1 — Dependency-safe payment release
  • Each payment is a map with string fields id, client, funding_account, amount, and depends_on. depends_on is an empty string or a comma-separated list of payment IDs; all referenced IDs exist in the batch.

  • All amounts are positive USD amounts with exactly two decimal places. Use exact integer-cent arithmetic.

  • Apply SINGLE_LIMIT: reject any payment whose amount is strictly greater than $10,000.00.

  • Apply CYCLE: reject every payment belonging to a directed dependency cycle, including a self-dependency. A payment merely downstream of a cycle is not itself a cycle member.

  • First identify all intrinsic failures. A payment violating both intrinsic rules receives both reasons, sorted lexicographically. Next reject every other payment reachable downstream from an intrinsic failure with the single reason DEPENDENCY_REJECTED.

  • Process the remaining payments by repeatedly selecting the lexicographically smallest ID whose prerequisites have all been approved. Approve that payment. Decisions are final.

  • Return one decision per payment, sorted by ID, with id, status (APPROVED or REJECTED), and a lexicographically sorted reasons list. Approved payments have no reasons. The implementation's return type is up to you; the examples show its required JSON representation.


release_payments(payments: list[dict[str, str]]) -> candidate_chosen_type
Example 1:
Input:
{
  "payments": [
    {"id":"P1","client":"C1","funding_account":"F1","amount":"6000.00","depends_on":""},
    {"id":"P2","client":"C1","funding_account":"F1","amount":"10000.01","depends_on":""},
    {"id":"P3","client":"C2","funding_account":"F2","amount":"5.00","depends_on":"P2"},
    {"id":"P4","client":"C2","funding_account":"F2","amount":"1.00","depends_on":"P5"},
    {"id":"P5","client":"C2","funding_account":"F2","amount":"2.00","depends_on":"P4"}
  ]
}

Output:
[
  {"id":"P1","status":"APPROVED","reasons":[]},
  {"id":"P2","status":"REJECTED","reasons":["SINGLE_LIMIT"]},
  {"id":"P3","status":"REJECTED","reasons":["DEPENDENCY_REJECTED"]},
  {"id":"P4","status":"REJECTED","reasons":["CYCLE"]},
  {"id":"P5","status":"REJECTED","reasons":["CYCLE"]}
]

Explanation: P1 is below the single-payment limit. P2 exceeds it by $0.01, so P3 cannot be released. P4 and P5 form a cycle; neither can fund the other first.
Part 2 — Configurable, overlapping batch budgets
Independent treasury-control teams now supply budget records. A payment can consume both a client budget and a funding-account budget, which Part 1's per-payment decisions cannot represent.
  • Extend the API to release_payments_with_caps(payments: list[dict[str, str]], caps: list[dict[str, str]]) -> candidate_chosen_type. Discuss how the return type changes before implementing this extension.

  • Each cap record has string fields id, field, value, and limit. field is currently client or funding_account; a cap matches when the payment's corresponding field equals value. Cap IDs are unique, but multiple caps may match the same field/value pair. Limits are nonnegative USD amounts with exactly two decimal places.

  • Preserve every Part 1 rule, including intrinsic-failure precedence, dependency rejection, and smallest-ready-ID processing. Budgets start at zero for each function call and count only approved payments in this batch.

  • For each otherwise eligible payment, evaluate all matching caps before changing any total. A cap fails precisely when approved_total + payment_amount > limit; equality is allowed. Reject the payment with CAP:<cap_id> for every failing cap, sorted lexicographically. Rejection consumes no budget, including from caps that would have passed.

  • When a cap rejects a payment, immediately reject its not-yet-final downstream dependents with DEPENDENCY_REJECTED. These dependents are not evaluated against caps.

  • If all caps pass, approve the payment and add its amount to every matching cap. An unmatched payment consumes no cap budget.

  • Return an object with decisions in Part 1's representation and cap_totals, a list sorted by cap ID. Each total is {"id": ..., "approved_amount": ...}, with exactly two decimal places; include unused caps with "0.00".

  • Design the rule mechanism to support future per-payment rules and new grouping fields without rewriting dependency traversal or scheduling. Do not build a general-purpose expression language.


Example 2:
Input:
{
  "payments": [
    {"id":"A","client":"C1","funding_account":"F1","amount":"6000.00","depends_on":""},
    {"id":"B","client":"C1","funding_account":"F2","amount":"4000.00","depends_on":"A"},
    {"id":"C","client":"C2","funding_account":"F1","amount":"3000.00","depends_on":""},
    {"id":"D","client":"C2","funding_account":"F1","amount":"4000.00","depends_on":"C"},
    {"id":"E","client":"C1","funding_account":"F2","amount":"1.00","depends_on":"B"}
  ],
  "caps": [
    {"id":"client-C1","field":"client","value":"C1","limit":"10000.00"},
    {"id":"fund-F1","field":"funding_account","value":"F1","limit":"12000.00"}
  ]
}

Output:
{
  "decisions": [
    {"id":"A","status":"APPROVED","reasons":[]},
    {"id":"B","status":"APPROVED","reasons":[]},
    {"id":"C","status":"APPROVED","reasons":[]},
    {"id":"D","status":"REJECTED","reasons":["CAP:fund-F1"]},
    {"id":"E","status":"REJECTED","reasons":["CAP:client-C1"]}
  ],
  "cap_totals": [
    {"id":"client-C1","approved_amount":"10000.00"},
    {"id":"fund-F1","approved_amount":"9000.00"}
  ]
}

Explanation: The selection order is A, B, C, D, E. A and B consume $6,000.00 + $4,000.00 = $10,000.00 of the C1 cap, exactly its limit. A and C consume $6,000.00 + $3,000.00 = $9,000.00 of the F1 cap. D would raise F1 to $13,000.00, exceeding $12,000.00; E would raise C1 to $10,001.00, exceeding $10,000.00. Neither rejection changes any total.
Example 3:
Input:
{
  "payments": [
    {"id":"A","client":"C1","funding_account":"F1","amount":"6000.00","depends_on":""},
    {"id":"B","client":"C1","funding_account":"F1","amount":"4000.00","depends_on":"A"},
    {"id":"C","client":"C1","funding_account":"F1","amount":"3000.00","depends_on":"B"},
    {"id":"D","client":"C2","funding_account":"F2","amount":"1.00","depends_on":"C"}
  ],
  "caps": [
    {"id":"client-C1","field":"client","value":"C1","limit":"10000.00"},
    {"id":"fund-F1","field":"funding_account","value":"F1","limit":"12000.00"}
  ]
}

Output:
{
  "decisions": [
    {"id":"A","status":"APPROVED","reasons":[]},
    {"id":"B","status":"APPROVED","reasons":[]},
    {"id":"C","status":"REJECTED","reasons":["CAP:client-C1","CAP:fund-F1"]},
    {"id":"D","status":"REJECTED","reasons":["DEPENDENCY_REJECTED"]}
  ],
  "cap_totals": [
    {"id":"client-C1","approved_amount":"10000.00"},
    {"id":"fund-F1","approved_amount":"10000.00"}
  ]
}

Explanation: A and B contribute $6,000.00 + $4,000.00 = $10,000.00 to both caps. C would raise each total to $13,000.00, simultaneously exceeding C1's $10,000.00 limit and F1's $12,000.00 limit. Both reasons are returned, neither total changes, and D is rejected without a budget evaluation because C failed.
Notes:
  • Support up to 200,000 payments, 400,000 dependency references, and 200,000 caps. Let M denote the total number of payment-to-cap matches; avoid scanning every cap for every payment.

  • Payment IDs are unique, dependency lists have no duplicate IDs or whitespace, and all required fields and references are valid. IDs use ASCII letters, digits, and hyphens; string ordering is ordinary case-sensitive lexicographic ordering.

  • Amounts and limits are at most $1,000,000,000.00. This is a single-process batch computation, not a live payment-execution or concurrency problem. You may use an AI assistant, but must explain and test cycle membership, rejection propagation, and atomic budget accounting.
Want to practise this one?
Create a free account to open the full question and practise Goldman Sachs questions with AI.
Sign up free
coding Hard caching #2

2. [Caching] — Implement an LFU cache with LRU tie-breaking


Background
Goldman Sachs analytics workflows, such as those supported by Marquee, involve repeated access to financial data and computed results. A bounded in-memory cache can reduce repeated retrieval or computation; this exercise models its eviction policy, not Marquee's actual implementation. An LFU cache question was reported in a January 2026 Goldman Sachs Analyst interview account.
Problem statement
Implement an LFUCache that stores integer key-value pairs up to a fixed capacity. When inserting a new key into a full cache, evict the key with the lowest access frequency. If multiple keys share that frequency, evict the least recently used among them.
The behavior must be deterministic:
  • A newly inserted key starts with frequency 1 and becomes the most recently used key at that frequency.

  • A successful get returns the stored value, increments the key's frequency by 1, and updates its recency.

  • A failed get returns -1 and changes nothing.

  • A put for an existing key replaces its value, increments its frequency by 1, and updates its recency. It must not evict another key.

  • A put for a new key evicts one resident key if necessary, then inserts the new key.

  • With capacity 0, every put has no effect and every get returns -1.

  • An evicted key loses its frequency history; reinserting it starts at frequency 1.


Both get and put must run in O(1) average time. Recency is determined solely by method-call order; no wall-clock timestamps are needed.
Class signature
  • LFUCache(capacity: int) — initialize an empty cache.

  • get(key: int) -> int — return the value or -1.

  • put(key: int, value: int) -> None — insert or update a key.


Example 1:
Input:
{
  "operations": ["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"],
  "arguments": [[2], [1, 10], [2, 20], [1], [3, 30], [2], [3], [4, 40], [1], [3], [4]]
}

Output:
[null, null, null, 10, null, -1, 30, null, -1, 30, 40]

Explanation: Reading key 1 raises its frequency to 2, so inserting key 3 evicts key 2, whose frequency is 1. Reading key 3 then raises its frequency to 2. Keys 1 and 3 now tie, but key 1 was used less recently, so inserting key 4 evicts key 1.
Example 2:
Input:
{
  "operations": ["LFUCache", "put", "put", "put", "put", "put", "get", "get", "get"],
  "arguments": [[2], [7, 70], [8, 80], [7, 75], [8, 85], [9, 90], [7], [8], [9]]
}

Output:
[null, null, null, null, null, null, -1, 85, 90]

Explanation: Updating keys 7 and 8 raises both frequencies from 1 to 2. Key 7 was updated first, so it is the least recently used at frequency 2 and is evicted when key 9 arrives. Updates count as accesses even when no get occurs.
Constraints:
  • 0 <= capacity <= 100000.

  • 0 <= key <= 1000000000.

  • 0 <= value <= 1000000000; therefore, -1 unambiguously indicates a miss.

  • At most 200000 calls to get and put follow construction.

  • Calls are sequential; thread safety and expiration are not required.

  • Use O(capacity) auxiliary space.


Follow-up:
Extend the cache with delete(key: int) -> bool, also in O(1) average time. Deleting the final key in the minimum-frequency bucket must correctly identify the next minimum even when frequency values have large gaps. What additional linked structure would you maintain?
coding Hard graph #3

3. Graph — Find shortest path in a stock transaction graph

Background: Goldman Sachs often deals with stock transactions, where understanding the pathways between stocks can lead to optimizations in trading strategies. This problem is essential for developing applications that recommend stock trades based on historical trends.
Problem statement: You are tasked with creating a function that finds the shortest path between two stocks in a weighted graph. Each node represents a stock, and edges represent transaction potentials with weights indicating transaction costs. Given a directed graph, return the shortest path from stock start to stock end. If there is no path, return -1.
Function/class signature:
  • def find_shortest_path(graph: Dict[str, Dict[str, int]], start: str, end: str) -> Union[int, List[str]]:

Example 1:
  • Input: graph = {'A': {'B': 5, 'C': 10}, 'B': {'C': 3, 'D': 1}, 'C': {'D': 2}, 'D': {}}

  • Output: [A, B, C, D]

  • Explanation: The shortest path from A to D is A -> B -> C -> D with a total cost of 5 + 3 + 2 = 10.

Example 2:
  • Input: graph = {'A': {'B': 2}, 'B': {'C': 2}, 'C': {'A': 1}}

  • Output: -1

  • Explanation: There is no path from A to C in this circular transaction graph.

Constraints:
  • The number of stocks (nodes) is between 1 and 1000.

  • The number of transactions (edges) can be at most 10,000.

  • Stocks are represented by uppercase letters A-Z.

  • Weights of edges are positive integers up to 1000.
coding Hard graph #4

4. [Graph] — Shortest Path in a Stock Trading Algorithm

Background: Goldman Sachs operates in a fast-paced trading environment where decisions are based on real-time data and market conditions. Efficiently determining the shortest path in stock transactions can lead to reduced latency and improved trading strategies.
Problem statement: You are given a directed graph where each node represents a stock and the edges represent the transaction costs between stocks. Your task is to find the minimum transaction cost to move from one stock to another. Implement a function min_transaction_cost that takes in the following parameters:
  • stock_count: int: Number of stocks (nodes in the graph)

  • edges: List[Tuple[int, int, int]]: A list of tuples, where each tuple represents a directed edge in the form (source, destination, cost).

  • start: int: Starting stock.

  • end: int: Target stock.

Returns the minimum transaction cost to get from start to end. If no path exists, return -1.
Function/class signature:
  • def min_transaction_cost(stock_count: int, edges: List[Tuple[int, int, int]], start: int, end: int) -> int:

Example 1:
Input: stock_count = 5, edges = [(0, 1, 100), (1, 2, 100), (1, 3, 200), (3, 4, 100)], start = 0, end = 4
Output: 300
Explanation: The shortest path is from 0 -> 1 -> 3 -> 4 with a total cost of 300.
Example 2:
Input: stock_count = 5, edges = [(0, 1, 100), (1, 2, 100), (1, 3, 200), (3, 2, 50), (2, 4, 100)], start = 0, end = 4
Output: 350
Explanation: The shortest path is from 0 -> 1 -> 2 -> 4 with a total cost of 350.
Constraints:
  • 1 <= stock_count <= 1000

  • 0 <= edges.length <= 2000

  • 0 <= cost <= 10^4

  • All stock indices in edges will be between 0 and stock_count - 1.

Start practicing Goldman Sachs questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free