3456. Find Special Substring of Length K Easy
1/**
2 * [3456] Find Special Substring of Length K
3 *
4 * You are given a string s and an integer k.
5 * Determine if there exists a <span data-keyword="substring-nonempty">substring</span> of length exactly k in s that satisfies the following conditions:
6 * <ol>
7 * The substring consists of only one distinct character (e.g., "aaa" or "bbb").
8 * If there is a character immediately before the substring, it must be different from the character in the substring.
9 * If there is a character immediately after the substring, it must also be different from the character in the substring.
10 * </ol>
11 * Return true if such a substring exists. Otherwise, return false.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "aaabaaa", k = 3</span>
16 * Output: <span class="example-io">true</span>
17 * Explanation:
18 * The substring s[4..6] == "aaa" satisfies the conditions.
19 *
20 * It has a length of 3.
21 * All characters are the same.
22 * The character before "aaa" is 'b', which is different from 'a'.
23 * There is no character after "aaa".
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">s = "abc", k = 2</span>
28 * Output: <span class="example-io">false</span>
29 * Explanation:
30 * There is no substring of length 2 that consists of one distinct character and satisfies the conditions.
31 * </div>
32 *
33 * Constraints:
34 *
35 * 1 <= k <= s.length <= 100
36 * s consists of lowercase English letters only.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/find-special-substring-of-length-k/
42// discuss: https://leetcode.com/problems/find-special-substring-of-length-k/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn has_special_substring(s: String, k: i32) -> bool {
48 false
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3456() {
60 }
61}
62Back
© 2026 bowen.ge All Rights Reserved.