← Goldman Sachs Interview Insights

Goldman Sachs·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Goldman Sachs SWE interview with a classic sliding window problem. Nothing too crazy but the follow-up asking you to return the actual substring tripped me up a bit since I'd only rehearsed the length version.

Questions Asked (1)

Q1

Given a string, find the length of the longest substring with no repeating characters. Follow-up: return the actual substring, not just its length. Walk through edge cases like an empty string, all identical characters, or all unique characters.

Algorithms & Data Structures
Author's notes

I had the sliding window approach down pretty cold, hash map tracking last-seen index, O(n), the whole thing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the sliding window technique 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. For the follow-up, maintain the start index of the current longest substring and update it whenever a new maximum is found. Walk through edge cases like empty string, all identical characters, and all unique characters to demonstrate thoroughness.

Pro tip: At Goldman Sachs, interviewers value clean, efficient code and clear communication. Before coding, briefly explain the brute-force approach and its O(n^2) or O(n^3) complexity, then optimize to O(n) with sliding window, showing you understand trade-offs.

1. Clarify and confirm requirements

Ask if the string contains only ASCII characters or Unicode, and confirm that we need the length and the substring itself. Also clarify if the substring must be contiguous (yes, by definition).

2. Discuss brute-force and optimal approach

Mention that a brute-force check of all substrings would be O(n^3) or O(n^2) with a set, then propose the sliding window with hash map for O(n) time and O(min(n, alphabet)) space.

3. Walk through the algorithm with an example

Use a simple example like 'abcabcbb' to illustrate how the window expands and contracts, and how the hash map stores the last index of each character to jump the left pointer efficiently.

4. Handle edge cases explicitly

Cover empty string (return 0 and empty substring), all identical characters (length 1, substring of one char), all unique characters (length n, whole string), and strings with spaces or special characters.

5. Code and test

Write clean code with meaningful variable names, then test with the edge cases and a few normal cases. For the follow-up, track the start index of the max window and return the substring using slicing.

Key Points to Mention

  • Sliding window technique with two pointers (left and right) to maintain a window of unique characters.
  • Hash map (or array for ASCII) to store the last seen index of each character, allowing O(1) updates.
  • Time complexity O(n) and space complexity O(min(n, m)) where m is the alphabet size.
  • For the follow-up, maintain variables for max length and start index of the longest substring, updating when a new max is found.
  • Edge cases: empty string, single character, all identical characters, all unique characters, and strings with repeated patterns.
  • Communication: explain thought process, discuss trade-offs, and test code with examples.

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