Trains the technique from
LeetCode 3302Find the Lexicographically Smallest Valid SequenceThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tape reel carries a long strip of lowercase letters, word1. A test rig needs to punch a probe hole at some of the slots so that reading the punched slots front to back reproduces a short target strip, word2.
Pick strictly increasing slot numbers p[0] < p[1] < ... < p[m-1], where m is the length of word2. The rig tolerates at most one disagreement: the number of positions t with word1[p[t]] != word2[t] may be 0 or 1, never more.
Among all tolerable choices, return the one whose slot list is lexicographically smallest: compare two lists entry by entry from the front, and the list with the smaller entry at the first differing spot wins. If no tolerable choice exists, return an empty array.
Example 1
Slots 1 and 2 are increasing and read `aa` against the target `ab`, which is one disagreement, so the choice is tolerable.
Example 2
Slots 0 and 3 read `ad` against the target `cd`, disagreeing only at the first position.
Example 3
Every pair of slots reads `aa`, which disagrees with `bb` in both positions, so the empty array is returned.
Example 4
Slots 0, 3 and 4 are increasing and read `cbc` against `abc`, a single disagreement at the first position.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def cheapest_probe_slots(reel: str, pattern: str) -> list[int]:public int[] cheapestProbeSlots(String reel, String pattern)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.