Longest Subsequence of Build Numbers Advancing by a Fixed Step

Last updated: November 29, 2026

Quick Overview

A CI system logs build numbers in the order they finished, and you want the longest subsequence whose values increase by exactly d from one element to the next. Return its length.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A CI system logs build numbers in the order they finished, and you want the longest subsequence whose values increase by exactly d from one element to the next. Return its length.

Google uses this as a check on hash-map DP, where the state is keyed by value instead of index. A strong candidate moves from an O(n^2) scan to O(n) with a dictionary and explains why only the latest occurrence matters.

What the Interviewer Expects
  • Define best[v] as the longest valid subsequence ending with value v
  • Update best[v] from best[v - d]
  • Use a dictionary since values are sparse
  • Explain why overwriting with later occurrences is safe
  • Handle d = 0 and negative d
Key Topics to Cover
1D dynamic programming
Hash map DP
Arithmetic subsequence
Order-dependent state
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Find the longest arithmetic subsequence with any common difference.
  • Return the actual indices of the subsequence.
  • Values arrive as a stream with deletions.
  • Allow at most one skipped step (a jump of 2d) in the chain.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list b of integers and integer d (any sign). Output the length of the longest subsequence b[i1], b[i2], ... with i1 < i2 < ... and each next value equal to the previous plus d. A single e...

High-Level Design

Process elements in order. Let best[v] be the longest valid subsequence ending in value v among elements seen so far. For a new element v, it can extend any chain ending in v - d: `best[v] = best....


Submit Your Answer
Markdown supported