FastPrepCan Subsequences Share One Master Sequence?
Problems/Can Subsequences Share One Master Sequence?

Can Subsequences Share One Master Sequence?

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks whether two subsequences can belong to one master sequence. It says "consistent" means their relative order is compatible, without giving the master sequence. It then extends to n subsequences with topological sorting. We chose that tokens in the master are unique, that edges link adjacent items, the string encoding, the examples, and the input limits. Our version is about 84% the same as the reported question.

You are given subsequences, a list of rows. Each row lists distinct tokens in the order they must appear.

A master sequence contains every distinct token exactly once. It must also hold the tokens of each row in that row’s order. Those tokens do not have to be next to each other.

Return true if such a master sequence exists, otherwise return false. You do not need to build the master sequence.

Function

canShareMasterSequence(subsequences: String[][]) → boolean

Examples

Example 1

subsequences = [["a","b"],["a","c"]]return = true

Both rows are subsequences of [a,b,c].

Example 2

subsequences = [["a","b"],["b","a"]]return = false

The first row requires a before b, while the second requires the reverse.

Example 3

subsequences = [["a","c"],["a","b","c"],["b","d"]]return = true

In [a,b,c,d], a comes before c, and a, b, c appear in that order. Also b comes before d. Every row keeps its order, so the answer is true.

Constraints

  • 1 <= subsequences.length <= 100000.
  • Every row contains from 1 through 100000 distinct tokens.
  • The total number of token occurrences is at most 200000.
  • Every token is a non-empty lowercase English string of length at most 30.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEW
  • Validate and Complete Racer PrecedenceMicrosoft · ONSITE INTERVIEW
  • Password From Ordering HintsRogo · ONSITE INTERVIEW
  • Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEW
  • Alien DictionaryBloomberg LP · ONSITE INTERVIEW
  • Alien DictionaryAmazon · ONSITE INTERVIEW
  • Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEW
  • Alien DictionaryAirbnb · PHONE SCREEN · ONSITE INTERVIEW
  • Validate CSV References and Field DependenciesStripe · PHONE SCREEN
  • Alien DictionaryIntuit · OA
See Google hiring insights
Saved
class Solution {
    public boolean canShareMasterSequence(String[][] subsequences) {
        // write your code here
    }
}
Checking account…