Search⌘ K
AI Features

Solution: Find Beautiful Indices in the Given Array II

C# solution for the Find Beautiful Indices in the Given Array II problem using the Two Pointers pattern.

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:

  • 11 \leq ...