2026 Goldman Sachs Coding Interview Real Questions & Solutions

Published: (April 17, 2026 at 02:59 AM EDT)
2 min read
Source: Dev.to

Source: Dev.to

Problem 1: Transaction Segments

Problem Summary:
(details omitted in the original post)

Key Idea:
(details omitted in the original post)

Problem 2: Efficient Tasks

Problem Summary:
(details omitted in the original post)

Key Idea:
(details omitted in the original post)

Problem 3: Design HashMap

Problem Statement
Implement a simple hash map with the following operations:

  • MyHashMap() – initialize the data structure
  • put(key, value) – insert or update a key‑value pair
  • get(key) – return the value associated with key, or -1 if the key does not exist
  • remove(key) – delete the key if it exists

Solution Idea

Use chaining to handle collisions. The structure contains a fixed‑size bucket array, where each bucket stores key‑value pairs in a list.

  • Hash function: key % bucket_size
  • Collision handling: list‑based chaining
  • Operations: linear search within each bucket

Python Implementation

class MyHashMap:
    def __init__(self, bucket_size: int = 1000):
        self.bucket_size = bucket_size
        self.buckets = [[] for _ in range(bucket_size)]

    def _hash(self, key: int) -> int:
        return key % self.bucket_size

    def put(self, key: int, value: int) -> None:
        idx = self._hash(key)
        bucket = self.buckets[idx]
        for i, (k, _) in enumerate(bucket):
            if k == key:
                bucket[i] = (key, value)   # update existing
                return
        bucket.append((key, value))          # insert new

    def get(self, key: int) -> int:
        idx = self._hash(key)
        bucket = self.buckets[idx]
        for k, v in bucket:
            if k == key:
                return v
        return -1

    def remove(self, key: int) -> None:
        idx = self._hash(key)
        bucket = self.buckets[idx]
        for i, (k, _) in enumerate(bucket):
            if k == key:
                bucket.pop(i)
                return

Complexity

  • Average Time: O(1) per operation
  • Worst‑Case Time: O(n) (when all keys collide into a single bucket)
  • Space: O(n) for storing the key‑value pairs

Interview Tips

  • Focus on explaining edge cases clearly.
  • Communicate your thought process while coding.
  • Be prepared for follow‑up questions on rehashing, load factor, and alternative collision‑resolution strategies.
  • Practice LeetCode Medium problems across categories such as Array, Dynamic Programming, Greedy, and Design.

Good luck with your Goldman Sachs interview preparation!

0 views
Back to Blog

Related posts

Read more »