Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3006 - Find Beautiful Indices in the Given Array I\.

    Medium

    You are given a 0-indexed string s, a string a, a string b, and an integer k.

    An index i is beautiful if:

    • 0 <= i <= s.length - a.length

    • s[i..(i + a.length - 1)] == a

    • There exists an index j such that:

    Return the array that contains beautiful indices in sorted order from smallest to largest.

    Example 1:

    Input: s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15

    Output: 16,33

    Explanation: There are 2 beautiful indices: 16,33.

    • The index 16 is beautiful as s16..17 == "my" and there exists an index 4 with s4..11 == "squirrel" and |16 - 4| <= 15.

    • The index 33 is beautiful as s33..34 == "my" and there exists an index 18 with s18..25 == "squirrel" and |33 - 18| <= 15. Thus we return 16,33 as the result.

    Example 2:

    Input: s = "abcd", a = "a", b = "a", k = 4

    Output: 0

    Explanation: There is 1 beautiful index: 0.

    • The index 0 is beautiful as s0..0 == "a" and there exists an index 0 with s0..0 == "a" and |0 - 0| <= 4. Thus we return 0 as the result.

    Constraints:

    • <code>1 <= k <= s.length <= 10<sup>5</sup></code>

    • 1 &lt;= a.length, b.length &lt;= 10

    • s, a, and b contain only lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final List<Integer> beautifulIndices(String s, String a, String b, Integer q)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait