← Yahoo Interview Insights

Yahoo·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Interviewed for a frontend engineer role at Yahoo and got hit with a classic dynamic programming problem. Nothing too wild but it definitely required some thinking on the spot.

Questions Asked (1)

Q1

Given an array of integers, find the maximum sum of a subsequence where no two selected elements are adjacent.

Algorithms & Data Structures
Author's notes

I knew this was a DP problem pretty quickly but fumbled the base cases at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose a dynamic programming solution that builds up the maximum sum by considering each element either included or excluded. Optimize space by keeping only the last two DP values, and analyze time and space complexity.

Pro tip: Mention that this is a classic DP problem similar to 'House Robber' and that you can achieve O(n) time and O(1) space, showing you recognize patterns and optimize beyond the naive approach.

1. Clarify and Define

Confirm that the subsequence can be non-contiguous, elements are integers (possibly negative), and we want maximum sum. Discuss edge cases like empty array, single element, all negatives.

2. Brute Force to DP

Acknowledge that brute force is exponential, then define DP state: dp[i] = max sum using first i elements. Derive recurrence: dp[i] = max(dp[i-1], dp[i-2] + arr[i-1]).

3. Optimize Space

Observe that dp[i] only depends on dp[i-1] and dp[i-2], so use two variables to reduce space to O(1).

4. Implement and Test

Write clean code, handle edge cases, and walk through a small example to verify correctness.

5. Analyze Complexity

State time complexity O(n) and space complexity O(1). Discuss potential follow-ups like circular array or returning the subsequence.

Key Points to Mention

  • Dynamic programming approach with optimal substructure
  • Recurrence relation: dp[i] = max(dp[i-1], dp[i-2] + arr[i-1])
  • Space optimization using two variables (O(1) space)
  • Handling edge cases: empty array, single element, negative numbers
  • Time complexity O(n) and space complexity O(1)
  • Similarity to House Robber problem

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