← Google Interview Insights

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

SeniorPrefer not to say
Jun 2026

Summary

Google SWE interview that went deep into sequence problems. The follow-up extension was the real test and I was not fully prepared for how far they'd push it.

Questions Asked (1)

Q1

Given N subsequences, determine whether they can all be subsequences of a single common parent sequence. If yes, construct or describe such a parent.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is the generalized version of a two-subsequence problem and it's a lot nastier.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as finding a shortest common supersequence (SCS) of the given subsequences, but note that for subsequences (not substrings), the order constraints are partial. Use a graph-based approach: create a DAG where edges represent required order between characters, then topologically sort to get a valid parent sequence. If cycles exist, no common parent exists.

Pro tip: Clarify with the interviewer whether the parent sequence must be minimal or any valid sequence is acceptable. Often, a simple concatenation with deduplication works if you respect order constraints, but discussing minimality shows depth.

1. Clarify requirements and constraints

Ask about input size, character set, whether the parent must be minimal, and if multiple valid parents are acceptable. This guides algorithm choice.

2. Model as a graph problem

Create a directed graph where each character occurrence is a node, and edges represent required order from each subsequence. For repeated characters, use indices to distinguish occurrences.

3. Detect cycles and find topological order

If the graph has a cycle, no common parent exists. Otherwise, a topological sort gives a valid parent sequence. Use Kahn's algorithm or DFS.

4. Optimize for minimality (if required)

If minimal parent is needed, this becomes NP-hard in general (shortest common supersequence for multiple strings). Discuss approximation or special cases (e.g., two sequences via DP).

5. Construct and verify

Output the topological order as the parent sequence. Verify by checking each input subsequence is indeed a subsequence of the parent.

Key Points to Mention

  • Shortest Common Supersequence (SCS) problem and its NP-hardness for multiple sequences
  • Graph representation: nodes as character occurrences, edges as order constraints
  • Cycle detection to determine feasibility
  • Topological sorting for construction
  • Special cases: two sequences solved via dynamic programming in O(n*m)
  • Trade-offs between minimality and computational complexity

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