Problem Challenge 2

We'll cover the following

String Anagrams (hard) #

Given a string and a pattern, find all anagrams of the pattern in the given string.

Anagram is actually a Permutation of a string. For example, “abc” has the following six anagrams:

  1. abc
  2. acb
  3. bac
  4. bca
  5. cab
  6. cba

Write a function to return a list of starting indices of the anagrams of the pattern in the given string.

Example 1:

Input: String="ppqp", Pattern="pq"
Output: [1, 2]
Explanation: The two anagrams of the pattern in the given string are "pq" and "qp".

Example 2:

Input: String="abbcabc", Pattern="abc"
Output: [2, 3, 4]
Explanation: The three anagrams of the pattern in the given string are "bca", "cab", and "abc".

Try it yourself #

Try solving this question here:

0 of 2 Tests Passed
ResultInputExpected OutputActual OutputReason
findStringAnagrams(ppqp, pq)[1, 2][]Incorrect Output
findStringAnagrams(abbcabc, abc)[2, 3, 4][]Incorrect Output
3.888s
Mark as Completed
←    Back
Solution Review: Problem Challenge 1
Next    →
Solution Review: Problem Challenge 2