Practice Find the Lexicographically Smallest Valid Sequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find the Lexicographically Smallest Valid Sequence
Problem Statement
Given word1 and word2, choose strictly increasing indices in word1 whose characters form a string differing from word2 in at most one position. Return the lexicographically smallest valid array of indices, with length word2.length, or an empty array if none exists. Minimize the index array itself, not the selected character string.
Source: Find the Lexicographically Smallest Valid Sequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
word1 = "vbcca", word2 = "abc"
[0,1,2]
# Example 2
word1 = "bacdc", word2 = "abc"
[1,2,4]
# Example 3
word1 = "aaaaaa", word2 = "aaabc"
[]
# Example 4
word1 = "abc", word2 = "ab"
[0,1]
Constraints
Related LeetCode Problems
Practice more problems similar to Find the Lexicographically Smallest Valid Sequence.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.