2506. Count Pairs Of Similar Strings Easy

@problem@discussion
#Array#Hash Table#String



1/**
2 * [2506] Count Pairs Of Similar Strings
3 *
4 * You are given a 0-indexed string array words.
5 * Two strings are similar if they consist of the same characters.
6 * 
7 * 	For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'.
8 * 	However, "abacba" and "bcfd" are not similar since they do not consist of the same characters.
9 * 
10 * Return the number of pairs (i, j) such that 0 <= i < j <= word.length - 1 and the two strings words[i] and words[j] are similar.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: words = ["aba","aabb","abcd","bac","aabc"]
15 * Output: 2
16 * Explanation: There are 2 pairs that satisfy the conditions:
17 * - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'. 
18 * - i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'. 
19 * 
20 * <strong class="example">Example 2:
21 * 
22 * Input: words = ["aabb","ab","ba"]
23 * Output: 3
24 * Explanation: There are 3 pairs that satisfy the conditions:
25 * - i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'. 
26 * - i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.
27 * - i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.
28 * 
29 * <strong class="example">Example 3:
30 * 
31 * Input: words = ["nba","cba","dba"]
32 * Output: 0
33 * Explanation: Since there does not exist any pair that satisfies the conditions, we return 0.
34 *  
35 * Constraints:
36 * 
37 * 	1 <= words.length <= 100
38 * 	1 <= words[i].length <= 100
39 * 	words[i] consist of only lowercase English letters.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/count-pairs-of-similar-strings/
45// discuss: https://leetcode.com/problems/count-pairs-of-similar-strings/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn similar_pairs(words: Vec<String>) -> i32 {
51        0
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_2506() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.