ORIGINAL CODING QUESTION
Common opening of all skill paths
Each learning path is a sequence of skill tokens. Return the length of the longest token sequence that every path starts with. A path cannot share more tokens than it has, and if the first tokens already disagree the answer is 0.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n paths. Each word is written as its length L followed by its L tokens.
Constraints
1 ≤ n ≤ 50; 1 ≤ L ≤ 20; every token is an integer in [1,26].
Example 1
Input
3 4 1 2 3 4 3 1 2 9 2 1 2
Output
2
All three paths start with 1, 2; the third path ends there.
Example 2
Input
2 2 3 4 2 4 3
Output
0
The first tokens differ, so nothing is shared.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
The shortest path caps the answer.
Hint 2
In a trie of all paths, the shared opening is the single-branch stretch from the root.
Hint 3
Stop when a node branches or when some path ends there.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →