← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Google SWE coding round with a subarray problem that had a tricky follow-up. The base question was manageable but the 'one modification allowed' variant is where things got interesting.

Questions Asked (1)

Q1

Given an integer array, find the length of the longest strictly increasing contiguous subarray. Then, as a follow-up: if you're allowed to change at most one element to any value, what's the maximum length you can achieve?

Algorithms & Data Structures
Author's notes

The base case is pretty standard sliding window stuff, got through it fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem and edge cases, then present a linear scan for the basic version, tracking the current increasing run length. For the follow-up, explain how to extend the scan by considering the effect of changing one element, using precomputed increasing run lengths from the left and right to efficiently compute the maximum length after a single modification.

Pro tip: Explicitly state the time and space complexity of your solution and discuss potential optimizations or alternative approaches, as Google interviewers value efficiency and depth of analysis.

1. Clarify the problem

Ask clarifying questions: Is the array non-empty? Can the array contain negative numbers? For the follow-up, can we change an element to any integer, including one already present? Confirm that 'contiguous subarray' means a contiguous segment of the array.

2. Solve the basic version

Propose a single-pass algorithm: iterate through the array, maintain a current length of the strictly increasing contiguous subarray, update the maximum length, and reset the current length when the increasing order breaks. State the O(n) time and O(1) space complexity.

3. Analyze the follow-up

Explain that changing one element can potentially merge two increasing runs separated by a single element. To handle this efficiently, precompute for each index the length of the increasing run ending at that index (left to right) and the length of the increasing run starting at that index (right to left).

4. Compute maximum with one change

Iterate through the array, and for each index i, consider changing nums[i] to bridge the left run ending at i-1 and the right run starting at i+1. If nums[i-1] + 1 < nums[i+1], the new length is left[i-1] + 1 + right[i+1]; otherwise, it's max(left[i-1], right[i+1]) + 1. Also consider changing the first or last element to extend a run. Keep track of the global maximum.

5. Test and discuss edge cases

Walk through examples, including arrays that are already strictly increasing, arrays with all equal elements, and arrays where changing one element doesn't help. Discuss time and space complexity: O(n) time and O(n) space for the precomputed arrays, with possible optimization to O(1) space if needed.

Key Points to Mention

  • Definition of strictly increasing contiguous subarray
  • Single-pass O(n) algorithm for the basic version
  • Precomputation of increasing run lengths from left and right
  • Condition for merging two runs when changing one element: nums[i-1] + 1 < nums[i+1]
  • Handling edge cases: changing first or last element, arrays of length 1 or 2
  • Time and space complexity analysis: O(n) time, O(n) space (or O(1) with optimization)

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