#2023
Medium Algorithms Number of pairs of strings with concatenation equal to target
Array Hash Table String Counting
75.4% acceptance
Feb 25, 2026
748
57
Given an array of digit strings nums and a digit string target, return the number of pairs (i,j)
where i != j such that nums[i] + nums[j] == target.
Solution
Rust
Time O(n²)
Space O(1)
impl Solution {
pub fn num_of_pairs(nums: Vec<String>, target: String) -> i32 {
let mut count = 0;
let n = nums.len();
for i in 0..n {
for j in 0..n {
if i != j {
let concat = format!("{}{}", nums[i], nums[j]);
if concat == target { count += 1; }
}
}
}
count
}
}