text and pattern, with pattern the shorter one.
Pick exactly len(pattern) positions of text in increasing order and read the letters at them. The pick is valid if the resulting string equals pattern or differs from it in exactly one letter (you may replace one letter).
Return the valid pick, as a list of positions, that is smallest in dictionary order when compared as a list of numbers (first position first, then the second on a tie, and so on). If there is no valid pick, return an empty list.
Note that it is the list of positions that must be smallest, not the string of picked letters.text="xcaty", pattern="bat" → [0, 2, 3]
Pick positions 0, 2, 3: the letters "xat". Replacing x with b gives "bat". The set [1, 2, 3] also works, but [0, 2, 3] is smaller.
text="cabd", pattern="abd" → [0, 2, 3]
The exact match is at positions [1, 2, 3]. But we can take position 0 and replace c with a, then find "bd" at 2 and 3: [0, 2, 3] is smaller.
text="aaaa", pattern="bcd" → []
At least two of the three letters must match, but text has no b, c or d, so the answer is empty.
text="xcaty", pattern="bat"
[0, 2, 3]
Run checks the first 3 tests in your browser. Submit checks all 154 tests on the server, hidden ones included.