← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE coding round, two parts to the same problem. The array version was fine, the stream follow-up is where things got interesting.

Questions Asked (2)

Q1

Given an array and an integer offset, return the first N elements if offset is positive, or the last N elements if offset is negative. For example, offset 2 on a five-element array gives you the first two; offset -3 gives you the last three.

Algorithms & Data Structures
Author's notes

Pretty clean to start.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying edge cases and constraints, then propose a simple solution using slicing or conditional logic. Discuss time and space complexity, and consider optimizations or alternative approaches.

Pro tip: Mention that you would handle edge cases like offset larger than array length or zero offset, and discuss whether to return a new array or modify in place.

1. Clarify requirements

Ask about input types, array size, offset range, and expected output format. Confirm edge cases like offset = 0 or offset > array length.

2. Outline approach

Explain that you will check the sign of offset: if positive, return first N elements; if negative, return last N elements. Use slicing or a loop.

3. Handle edge cases

Describe how to handle offset = 0, offset exceeding array length, and empty array. Decide on behavior (e.g., return empty array or clamp to bounds).

4. Analyze complexity

State that time complexity is O(N) for slicing or O(1) if returning a view, and space complexity is O(N) for a new array. Discuss trade-offs.

5. Test with examples

Walk through the given example and a few edge cases to verify correctness. Mention potential pitfalls like off-by-one errors.

Key Points to Mention

  • Use of array slicing (e.g., arr[:offset] or arr[offset:]) for concise code.
  • Handling negative offsets by converting to positive index from the end.
  • Edge cases: offset = 0, offset > array length, empty array.
  • Time and space complexity analysis.
  • Language-specific considerations (e.g., Python slicing vs Java loops).
  • Potential follow-up: in-place modification vs returning new array.

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

Q2

Now implement the same offset behavior but the input is a stream with hasNext() and getNext() methods. You don't know the size in advance. How do you handle both the positive and negative offset cases?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is the real question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the offset semantics: positive offset means skipping ahead, negative offset means going back. For a stream, use a circular buffer to handle negative offsets and a simple skip loop for positive offsets, while discussing trade-offs like memory usage and stream non-rewindability.

Pro tip: Mention that if the stream is not rewindable, negative offsets require buffering past elements, and you should ask whether the offset can exceed the buffer size or if the stream supports reset.

1. Clarify requirements and constraints

Ask about offset range, stream rewindability, memory limits, and whether multiple passes are allowed. This shows you consider practical constraints.

2. Handle positive offset

For positive offset k, simply call getNext() k times to skip ahead. Discuss edge cases like stream ending before k elements.

3. Handle negative offset

For negative offset -k, you need to go back k elements. Use a circular buffer of size k to store the last k elements as you read, then return the oldest buffered element.

4. Discuss trade-offs and alternatives

Compare buffer size vs. memory, consider if offset can be larger than buffer, and mention that if the stream is rewindable, you could reset and skip.

5. Provide code or pseudocode

Outline the implementation with a class that maintains a buffer and methods to handle both cases, ensuring O(1) amortized time per operation.

Key Points to Mention

  • Circular buffer for negative offsets to store past elements
  • Positive offset via skipping using getNext()
  • Stream non-rewindability and its implications
  • Memory trade-offs: buffer size proportional to maximum negative offset
  • Edge cases: offset larger than stream length, buffer overflow
  • Time complexity: O(k) for positive offset, O(1) per element for negative with buffer

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