← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Google SWE coding round, two related array problems back to back. The follow-up was the real interview, the first part was just warmup.

Questions Asked (2)

Q1

Given an integer array, find the longest strictly increasing contiguous subarray in a single pass with O(n) time complexity.

Algorithms & Data Structures
Author's notes

Pretty standard once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a single pass with two pointers or running counters to track the current increasing run and the best run seen so far. At each step, compare the current element with the previous one: if it's greater, extend the current run; otherwise, reset the current run to start at the current element. Update the best run whenever the current run exceeds it.

Pro tip: Clarify upfront that 'contiguous subarray' means a contiguous segment of the array, and confirm whether you need to return the subarray itself or just its length—this shows attention to detail and avoids wasted effort.

1. Clarify requirements and edge cases

Confirm the definition of 'strictly increasing' and whether the output should be the subarray or its length. Discuss edge cases like empty array, single element, and all decreasing elements.

2. Outline the single-pass approach

Explain that you'll iterate through the array once, maintaining the start index and length of the current increasing run, and the best run found so far.

3. Detail the iteration logic

For each element from index 1 to n-1, compare with the previous element. If it's greater, increment the current run length; otherwise, reset the current run to start at the current index with length 1. Update the best run if the current run is longer.

4. Handle initialization and return

Initialize current run length to 1 and best run to 1 (or handle empty array separately). After the loop, return the best run (or the subarray using the recorded start and length).

5. Analyze complexity and test

State that time complexity is O(n) and space complexity is O(1) (or O(n) if returning the subarray). Walk through a small example to verify correctness.

Key Points to Mention

  • Single pass with O(n) time and O(1) extra space (excluding output).
  • Maintain current run length and best run length, updating best when current exceeds it.
  • Reset current run when the increasing sequence breaks (i.e., when arr[i] <= arr[i-1]).
  • Track start index of the best run if the subarray itself must be returned.
  • Handle edge cases: empty array, single element, and strictly decreasing array.
  • Strictly increasing means each element must be greater than the previous, not equal.

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

Q2

Now extend the previous problem: you're allowed to replace at most one element in the array with any value you want. What's the longest strictly increasing contiguous subarray you can achieve, and how do you compute it efficiently?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things got messy for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem and confirm that the replacement can be any value, including values outside the current range. Then, propose an O(n) solution that precomputes the lengths of increasing runs ending and starting at each index, and for each potential replacement position, combines the run before and after if the gap can be bridged by a single value. Finally, discuss edge cases and trade-offs.

Pro tip: Mention that the replacement value can be chosen to satisfy the increasing condition if the difference between the boundary elements is at least 2, or if the replacement is at the array boundary. This shows attention to detail and avoids off-by-one errors.

1. Clarify the problem

Confirm that you can replace at most one element with any value, and that the subarray must be contiguous and strictly increasing. Ask if the replacement can be outside the original array's range.

2. Precompute increasing runs

Compute two arrays: inc_end[i] = length of longest strictly increasing subarray ending at i, and inc_start[i] = length of longest strictly increasing subarray starting at i. This can be done in O(n) time.

3. Evaluate replacement at each position

For each index i, consider replacing arr[i]. The best subarray including i is inc_end[i-1] + 1 + inc_start[i+1] if the gap between arr[i-1] and arr[i+1] can be bridged by a single value (i.e., arr[i+1] - arr[i-1] >= 2). Also consider replacing at boundaries (i=0 or i=n-1) where only one side exists.

4. Handle edge cases and return maximum

If no replacement is used, the answer is the maximum of inc_end[i]. Also consider arrays of length 1 or 2. Return the maximum over all valid combinations.

5. Analyze complexity and trade-offs

The algorithm runs in O(n) time and O(n) space. Discuss if space can be reduced to O(1) by computing runs on the fly, but note that precomputation simplifies the logic.

Key Points to Mention

  • Strictly increasing condition and how replacement can bridge gaps
  • Precomputation of inc_end and inc_start arrays for O(n) efficiency
  • Condition for bridging: arr[i+1] - arr[i-1] >= 2
  • Edge cases: replacement at boundaries, arrays of length 1 or 2
  • Time and space complexity: O(n) time, O(n) space, with possible O(1) space optimization
  • Comparison with the previous problem (without replacement) to highlight the added complexity

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