{"id":"9ecb184a-aaa4-4a8f-99d0-0e6ba5a2b156","name":"Find All Anagrams In A String","description":"1. You are given two strings s1 and s2.\r\n2. You have to find the count of s2's anagrams that are present in s1.\r\n3. Also, you have to print the start indices of such anagrams in s1.\r\n\r\nNote -> Both s1 ad s2 consist of lowercase English letters only.","inputFormat":"Two strings s1 and s2","outputFormat":"A number(x) representing count of s2's anagrams which are present in s1.\r\nX space separated numbers representing start indices of anagrams.","constraints":"1 &lt;= length of string &lt;= 20,000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nvoid findAnagrams(string s, string p) {\n // write your code here\n\n}\n\nint main() {\n\tstring s;\n\tstring p;\n\tcin >> s >> p;\n\tfindAnagrams(s, p);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void findAnagrams(String s, String p) {\r\n // write your code here\r\n \r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s = scn.next();\r\n\t\tString p = scn.next();\r\n\t\tfindAnagrams(s, p);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"cbaebabacd\r\nabc","sampleOutput":"2\r\n0 6 ","questionVideo":"https://www.youtube.com/embed/slDyFUnGtoU?end=126","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"5f3d6a43-3fbf-4fbd-836d-216ca48501a2","name":"Find All Anagrams In A String","slug":"find-all-anagrams-in-a-string","type":1}],"next":{"id":"2b2ffde6-29a1-49a2-b76d-60cde8665fbf","name":"Find All Anagrams In A String MCQ","type":0,"slug":"find-all-anagrams-in-a-string-mcq"},"prev":{"id":"33d850c8-d413-4ef1-b127-71f638047b69","name":"Count of Substrings with At Most K Unique Characters","type":3,"slug":"count-of-substrings-with-at-most-k-unique-characters"}}}

Find All Anagrams In A String

1. You are given two strings s1 and s2. 2. You have to find the count of s2's anagrams that are present in s1. 3. Also, you have to print the start indices of such anagrams in s1. Note -> Both s1 ad s2 consist of lowercase English letters only.

{"id":"9ecb184a-aaa4-4a8f-99d0-0e6ba5a2b156","name":"Find All Anagrams In A String","description":"1. You are given two strings s1 and s2.\r\n2. You have to find the count of s2's anagrams that are present in s1.\r\n3. Also, you have to print the start indices of such anagrams in s1.\r\n\r\nNote -> Both s1 ad s2 consist of lowercase English letters only.","inputFormat":"Two strings s1 and s2","outputFormat":"A number(x) representing count of s2's anagrams which are present in s1.\r\nX space separated numbers representing start indices of anagrams.","constraints":"1 &lt;= length of string &lt;= 20,000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n\nvoid findAnagrams(string s, string p) {\n // write your code here\n\n}\n\nint main() {\n\tstring s;\n\tstring p;\n\tcin >> s >> p;\n\tfindAnagrams(s, p);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void findAnagrams(String s, String p) {\r\n // write your code here\r\n \r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s = scn.next();\r\n\t\tString p = scn.next();\r\n\t\tfindAnagrams(s, p);\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"cbaebabacd\r\nabc","sampleOutput":"2\r\n0 6 ","questionVideo":"https://www.youtube.com/embed/slDyFUnGtoU?end=126","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"5f3d6a43-3fbf-4fbd-836d-216ca48501a2","name":"Find All Anagrams In A String","slug":"find-all-anagrams-in-a-string","type":1}],"next":{"id":"2b2ffde6-29a1-49a2-b76d-60cde8665fbf","name":"Find All Anagrams In A String MCQ","type":0,"slug":"find-all-anagrams-in-a-string-mcq"},"prev":{"id":"33d850c8-d413-4ef1-b127-71f638047b69","name":"Count of Substrings with At Most K Unique Characters","type":3,"slug":"count-of-substrings-with-at-most-k-unique-characters"}}}
plane

Editor


Loading...

Find All Anagrams In A String

medium

1. You are given two strings s1 and s2. 2. You have to find the count of s2's anagrams that are present in s1. 3. Also, you have to print the start indices of such anagrams in s1. Note -> Both s1 ad s2 consist of lowercase English letters only.

Constraints

1 <= length of string <= 20,000

Format

Input

Two strings s1 and s2

Output

A number(x) representing count of s2's anagrams which are present in s1. X space separated numbers representing start indices of anagrams.

Example

Sample Input

cbaebabacd abc

Sample Output

2 0 6

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode