2026 Goldman Sachs Coding Interview Real Questions & Solutions
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 structureput(key, value)– insert or update a key‑value pairget(key)– return the value associated withkey, or-1if the key does not existremove(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!