Skip to content

Practice Find Beautiful Indices in the Given Array I

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3006
LeetCode Problem

Find Beautiful Indices in the Given Array I

Problem Statement

Given strings s, a, b and an integer k, return all starting indices i where a occurs in s and there is a starting index j where b occurs in s with |i - j| <= k. Both occurrences must fit entirely in s. Return the indices i in ascending order.

Source: Find Beautiful Indices in the Given Array I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
Output
[16,33]

# Example 2

Input
s = "abcd", a = "a", b = "a", k = 4
Output
[0]

Constraints

1 <= k <= s.length <= 10^5
1 <= a.length, b.length <= 10
s, a, and b contain only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Find Beautiful Indices in the Given Array I.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.