@@ -0,0 +1,1786 @@
+package com.leetcode.strings;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A/**%0A * Leetcode Problem: https://leetcode.com/problems/find-all-anagrams-in-a-string/%0A * %0A * @author rampatra%0A * @since 2019-04-13%0A */%0Apublic class AnagramsInString %7B%0A%0A    private static List%3CInteger%3E findAllAnagramsInTextNaive(String text, String pattern) %7B%0A        List%3CInteger%3E indexes = new ArrayList%3C%3E();%0A        %0A        int textLen = text.length();%0A        int patternLen = pattern.length();%0A        %0A        char%5B%5D patternChars = pattern.toCharArray();%0A        Arrays.sort(patternChars); // takes O(m log m) time%0A        String sortedPattern = String.valueOf(patternChars);%0A        %0A        String subText;%0A        char%5B%5D subTextChars;%0A        String sortedSubText;%0A        %0A        for (int i = 0; i %3C= textLen - patternLen; i++) %7B // loops n-m number of times%0A            subText = text.substring(i, i + patternLen); %0A            subTextChars = subText.toCharArray();%0A            Arrays.sort(subTextChars); // sorts m number of characters, takes O(m log m)%0A            sortedSubText = String.valueOf(subTextChars);%0A            %0A            if (sortedSubText.equals(sortedPattern)) %7B // compare m characters takes m time%0A                indexes.add(i);%0A            %7D%0A        %7D%0A        return indexes;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        // basic use cases%0A        System.out.println(findAllAnagramsInTextNaive(%22cbaebabacd%22, %22abc%22));%0A        System.out.println(findAllAnagramsInTextNaive(%22abab%22, %22ab%22));%0A        %0A        // corner cases%0A        System.out.println(findAllAnagramsInTextNaive(%22abab%22, %22%22));%0A        System.out.println(findAllAnagramsInTextNaive(%22%22, %22ab%22));%0A        System.out.println(findAllAnagramsInTextNaive(%22%22, %22%22));%0A    %7D%0A%7D

Anagrams in string: naive sol. done