The Frequencies of Shortest Supersequences interview question is an advanced string and graph problem. You are given a set of short strings (or rules) and you need to find the shortest possible "supersequence" that contains all of them as subsequences. Since there can be multiple shortest supersequences, the problem specifically asks for the character frequencies of all valid shortest supersequences.
This is a highly complex Graph and Combinatorics coding problem asked by top-tier companies. It is an extension of the classic "Shortest Common Supersequence" problem. It evaluates a candidate's ability to combine Topological Sorting (to satisfy ordering constraints) with Bitmask DP or exhaustive search to handle conflicting orderings and find all minimal-length valid combinations.
This problem usually requires transforming the constraints into a Directed Graph and finding the optimal Topological Sort.
u -> v means character u must appear before v.Suppose rules are "ab" and "ba".
a -> b and b -> a. This is a cycle.a: 2, b: 1. Frequencies for "bab": a: 1, b: 2.
You would return both frequency sets.When dealing with multiple subsequence constraints, always think of Directed Graphs. A path in the graph represents a valid sequence. A cycle represents a contradiction that forces you to increase the length of your supersequence by duplicating nodes.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Naming a Company | Hard | Solve | |
| Find All Possible Recipes from Given Supplies | Medium | Solve | |
| Alien Dictionary | Hard | Solve | |
| Longest Path With Different Adjacent Characters | Hard | Solve | |
| Maximum Possible Number by Binary Concatenation | Medium | Solve |