Tap here to switch tabs
Problem
Submissions

Problem: Find the Lexicographically Smallest Valid Sequence

med
30 min
Try to solve the Find the Lexicographically Smallest Valid Sequence problem.

Statement

You are given two strings, word1 and word2.

A sequence of indices seq is considered valid if:

  • The length of seq is equal to the length of word2.

  • The indices are strictly increasing, satisfying 0≤0 \leq seq[0] << seq[1] <⋯<< \dots < seq[word2.length −1]- 1] << word1.length.

  • The string formed by concatenating word1[seq[0]], word1[seq[1]], …, word1[seq[word2.length −1]]- 1]] is almost equal to word2.

Two strings aa and bb of equal length are almost equal if they differ at at most 11 index.

Return an array representing the lexicographically smallest valid sequence of indices. If no valid sequence exists, return an empty array.

Note: An array a is lexicographically smaller than an array b if at the first index where they differ, the element in a is strictly less than the element in b.

Constraints:

  • 1≤1 \leq word2.length ≤\leq word1.length ≤3imes105\leq 3 imes 10^5

  • word1 and word2 consist only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Lexicographically Smallest Valid Sequence

med
30 min
Try to solve the Find the Lexicographically Smallest Valid Sequence problem.

Statement

You are given two strings, word1 and word2.

A sequence of indices seq is considered valid if:

  • The length of seq is equal to the length of word2.

  • The indices are strictly increasing, satisfying 0≤0 \leq seq[0] << seq[1] <⋯<< \dots < seq[word2.length −1]- 1] << word1.length.

  • The string formed by concatenating word1[seq[0]], word1[seq[1]], …, word1[seq[word2.length −1]]- 1]] is almost equal to word2.

Two strings aa and bb of equal length are almost equal if they differ at at most 11 index.

Return an array representing the lexicographically smallest valid sequence of indices. If no valid sequence exists, return an empty array.

Note: An array a is lexicographically smaller than an array b if at the first index where they differ, the element in a is strictly less than the element in b.

Constraints:

  • 1≤1 \leq word2.length ≤\leq word1.length ≤3imes105\leq 3 imes 10^5

  • word1 and word2 consist only of lowercase English letters.