Loading...
Loading...
Loading...
A text tool looks for places where a short word hides in a long text with its letters rearranged. Given a text s and a word p, print every start position (0-based) where a block of s of the same length as p is a rearrangement of p. Print -1 if there is none.
Example
Input
cbaebabacd abc
Output
0 6
The blocks "cba" at 0 and "bac" at 6 are rearrangements of "abc".
Try the problem first. Open one hint at a time.
Keep a Counter of the current block and compare it to the Counter of p.
When the block moves, add the new letter, remove the old one, and delete counts that reach 0.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor