3006. Find Beautiful Indices in the Given Array I Medium
1/**
2 * [3006] Find Beautiful Indices in the Given Array I
3 *
4 * You are given a 0-indexed string s, a string a, a string b, and an integer k.
5 * An index i is beautiful if:
6 *
7 * 0 <= i <= s.length - a.length
8 * s[i..(i + a.length - 1)] == a
9 * There exists an index j such that:
10 *
11 * 0 <= j <= s.length - b.length
12 * s[j..(j + b.length - 1)] == b
13 * |j - i| <= k
14 *
15 *
16 *
17 * Return the array that contains beautiful indices in sorted order from smallest to largest.
18 *
19 * <strong class="example">Example 1:
20 *
21 * Input: s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
22 * Output: [16,33]
23 * Explanation: There are 2 beautiful indices: [16,33].
24 * - The index 16 is beautiful as s[16..17] == "my" and there exists an index 4 with s[4..11] == "squirrel" and |16 - 4| <= 15.
25 * - The index 33 is beautiful as s[33..34] == "my" and there exists an index 18 with s[18..25] == "squirrel" and |33 - 18| <= 15.
26 * Thus we return [16,33] as the result.
27 *
28 * <strong class="example">Example 2:
29 *
30 * Input: s = "abcd", a = "a", b = "a", k = 4
31 * Output: [0]
32 * Explanation: There is 1 beautiful index: [0].
33 * - The index 0 is beautiful as s[0..0] == "a" and there exists an index 0 with s[0..0] == "a" and |0 - 0| <= 4.
34 * Thus we return [0] as the result.
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= k <= s.length <= 10^5
40 * 1 <= a.length, b.length <= 10
41 * s, a, and b contain only lowercase English letters.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/
47// discuss: https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn beautiful_indices(s: String, a: String, b: String, k: i32) -> Vec<i32> {
53 vec![]
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_3006() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.