Tap here to switch tabs
Problem
Submissions

Problem: Find Beautiful Indices in the Given Array II

med
30 min
Try to solve the Find Beautiful Indices in the Given Array II problem.

Statement

You are given strings s, a, and b, along with an integer k.

An index i is called beautiful if both conditions hold:

  1. The substring of s starting at i matches a, meaning s[i..i + len(a) - 1] == a.

  2. There exists an index j such that the substring of s starting at j matches b, meaning s[j..j + len(b) - 1] == b, and the distance between the starting indices satisfies |i - j| <= k.

Return all beautiful indices i in increasing order.

Constraints:

  • 1≤1 \leq k ≤\leq s.length ≤5⋅105\leq 5 \cdot 10^5

  • 1≤1 \leq a.length, b.length ≤5⋅105\leq 5 \cdot 10^5

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Beautiful Indices in the Given Array II

med
30 min
Try to solve the Find Beautiful Indices in the Given Array II problem.

Statement

You are given strings s, a, and b, along with an integer k.

An index i is called beautiful if both conditions hold:

  1. The substring of s starting at i matches a, meaning s[i..i + len(a) - 1] == a.

  2. There exists an index j such that the substring of s starting at j matches b, meaning s[j..j + len(b) - 1] == b, and the distance between the starting indices satisfies |i - j| <= k.

Return all beautiful indices i in increasing order.

Constraints:

  • 1≤1 \leq k ≤\leq s.length ≤5⋅105\leq 5 \cdot 10^5

  • 1≤1 \leq a.length, b.length ≤5⋅105\leq 5 \cdot 10^5

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