2399. Check Distances Between Same Letters Easy
1/**
2 * [2399] Check Distances Between Same Letters
3 *
4 * You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.
5 * Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).
6 * In a well-spaced string, the number of letters between the two occurrences of the i^th letter is distance[i]. If the i^th letter does not appear in s, then distance[i] can be ignored.
7 * Return true if s is a well-spaced string, otherwise return false.
8 *
9 * Example 1:
10 *
11 * Input: s = "abaccb", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
12 * Output: true
13 * Explanation:
14 * - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.
15 * - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.
16 * - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.
17 * Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.
18 * Return true because s is a well-spaced string.
19 *
20 * Example 2:
21 *
22 * Input: s = "aa", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
23 * Output: false
24 * Explanation:
25 * - 'a' appears at indices 0 and 1 so there are zero letters between them.
26 * Because distance[0] = 1, s is not a well-spaced string.
27 *
28 *
29 * Constraints:
30 *
31 * 2 <= s.length <= 52
32 * s consists only of lowercase English letters.
33 * Each letter appears in s exactly twice.
34 * distance.length == 26
35 * 0 <= distance[i] <= 50
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/check-distances-between-same-letters/
41// discuss: https://leetcode.com/problems/check-distances-between-same-letters/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn check_distances(s: String, distance: Vec<i32>) -> bool {
47 false
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2399() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.