← Waymo Interview Insights

Waymo·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Waymo SWE interview that came down to a DP/greedy problem on alternating subsequence sums. Not the hardest problem on paper but the two-state formulation takes a second to click if you haven't seen it before.

Questions Asked (1)

Q1

Given an integer array, find the maximum alternating subsequence sum, where the alternating sum of a subsequence is defined as the first element minus the second plus the third minus the fourth, and so on.

Algorithms & Data Structures
Author's notes

Took me longer than I'd like to admit to see why this reduces to two states.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose a dynamic programming solution that tracks the maximum alternating sum ending at each index with a positive or negative sign. Explain the recurrence and optimize space to O(1) if possible.

Pro tip: Discuss how the problem relates to stock trading with cooldown or maximum subarray sum, showing pattern recognition. Also, mention that the greedy approach of picking local extrema works for the maximum alternating sum of the entire array but not for subsequences, so DP is necessary.

1. Clarify the problem

Ask about constraints (array size, element range), whether the subsequence must be non-empty, and if the alternating sum can start with either sign. Confirm that subsequence means preserving order but not necessarily contiguous.

2. Define DP states

Let dp[i][0] be the maximum alternating sum of a subsequence ending at index i where the last operation was addition (i.e., the element is added). Let dp[i][1] be the maximum alternating sum where the last operation was subtraction (i.e., the element is subtracted).

3. Derive recurrence

For each element, dp[i][0] = max(dp[i-1][0], dp[i-1][1] + arr[i], arr[i]) and dp[i][1] = max(dp[i-1][1], dp[i-1][0] - arr[i]). The answer is max(dp[n-1][0], dp[n-1][1]).

4. Optimize space

Observe that only the previous state is needed, so we can reduce space to O(1) by keeping two variables: max_add and max_sub.

5. Analyze complexity and test

Time complexity is O(n) and space O(1). Walk through examples like [1,2,3] and [1,-2,3,-4] to verify correctness, and discuss edge cases like all negative numbers.

Key Points to Mention

  • Dynamic programming with two states: last operation was addition or subtraction.
  • Recurrence relations and initialization.
  • Space optimization from O(n) to O(1).
  • Time and space complexity analysis.
  • Handling edge cases: empty array, single element, all negatives.
  • Comparison with greedy approach for contiguous alternating sum.

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