Find All Anagrams in a String
Given a string original
and a string check
, find the starting index of all substrings
of original
that is an anagram of check
. The output must be sorted in ascending order.
Parameters
original
: A stringcheck
: A string
Result
- A list of integers representing the starting indices of all anagrams of
check
.
Examples
Example 1
Input: original = "cbaebabacd"
, check = "abc"
Output: [0, 6]
Explanation: The substring from 0
to 2
, "cba"
, is an anagram of "abc"
, and so is
the substring from 6
to 8
, "bac"
.
Example 2
Input: original = "abab"
, check = "ab"
Output: [0, 1, 2]
Explanation: All substrings with length 2
from "abab"
is an anagram of "ab"
.
Constraints
1 <= len(original), len(check) <= 10^5
- Each string consists of only lowercase characters in standard English alphabet.
Try it yourself
Solution
Title
Script
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
Contrary to popular belief, Lorem
Ipsum
is not simply random text.
1 >>> a = [1, 2, 3] 2 >>> a[-1] 3 3