Skip to content

ORIGINAL CODING QUESTION

Target glyph subsequence count

Count indexed subsequences of the first input equal to the second input. Return the count modulo 1,000,000,007.

Open practice workspace

Original exercise · hard. Editorial role relevance does not imply a company has asked this question.

Input and output

n, n glyph integers, m, m glyph integers. Print the requested integer.

Constraints

1 ≤ n,m ≤ 30; each glyph integer is in [0,25].

Example 1

Input

3 0 0 0 2 0 0

Output

3

Three indexed pairs form the target.

Example 2

Input

3 0 1 2 2 0 2

Output

1

One indexed subsequence matches.

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

Decide whether a source glyph is used or skipped.

Hint 2

Only matching glyphs can extend target matches.

Hint 3

Update a one-dimensional target table from right to left.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →