← Goldman Sachs Interview Insights

Goldman Sachs·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Goldman Sachs SWE coding round, pretty much a classic sliding window problem with a twist. Nothing too wild but the follow-up tripped me up a bit.

Questions Asked (1)

Q1

Given a string, find the length of the longest substring that contains no repeated characters. Follow-up: return the actual substring, not just its length.

Algorithms & Data Structures
Author's notes

I knew the sliding window approach going in, so the main part was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window with a hash map to track the last seen index of each character, expanding the right pointer and shrinking the left pointer when a duplicate is found. This yields O(n) time and O(min(n, alphabet)) space. For the follow-up, maintain the start index of the current longest window and extract the substring at the end.

Pro tip: At Goldman Sachs, interviewers value clean, efficient code and clear communication. Before coding, briefly explain the brute-force O(n^2) approach and why the sliding window improves it, then discuss edge cases like empty strings and all unique characters.

1. Clarify and Confirm

Ask clarifying questions: character set (ASCII/Unicode), case sensitivity, and expected input size. Confirm return type for follow-up (substring vs. length).

2. Outline Brute Force and Optimize

Mention the naive O(n^2) approach checking all substrings, then propose the sliding window with a hash map for O(n) time.

3. Implement Sliding Window

Initialize left=0, max_len=0, and a map char->last_index. Iterate right from 0 to n-1; if char in map and map[char] >= left, update left = map[char]+1. Update max_len and record start index if needed.

4. Handle Follow-Up

Maintain start and end indices of the longest window. After the loop, return s.substring(start, start+max_len) if asked for the substring.

5. Test and Analyze

Walk through edge cases: empty string, single character, all duplicates, all unique. State time O(n) and space O(min(n, alphabet)).

Key Points to Mention

  • Sliding window technique with two pointers (left and right).
  • Hash map to store the last seen index of each character for O(1) lookups.
  • Time complexity O(n) and space complexity O(min(n, alphabet)).
  • Handling edge cases: empty string, single character, all unique characters, all same characters.
  • For follow-up, tracking the start index of the longest substring to extract it.
  • Comparing with brute-force O(n^2) approach to highlight optimization.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.