#2937
Easy Algorithms Make three strings equal
String
44.6% acceptance
Feb 25, 2026
322
43
You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings
and delete its rightmost character. Note that you cannot completely empty a string.
Return the minimum number of operations required to make the strings equal.
If it is impossible to make them equal, return -1.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn find_minimum_operations(s1: String, s2: String, s3: String) -> i32 {
let s1 = s1.as_bytes();
let s2 = s2.as_bytes();
let s3 = s3.as_bytes();
// Find length of longest common prefix of all three
let min_len = s1.len().min(s2.len()).min(s3.len());
let mut common = 0;
while common < min_len && s1[common] == s2[common] && s1[common] == s3[common] {
common += 1;
}
if common == 0 { return -1; }
(s1.len() + s2.len() + s3.len() - 3 * common) as i32
}
}