Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;

int minChanges(string &a, string &b, string &c) {
    int n = a.length(), m = b.length();
    vector<int> prev(m + 1, 0), curr(m + 1, 0);

    // Initialize base cases
    for (int j = 0; j <= m; ++j) {
        prev[j] = j; // Only use characters from `b`
    }

    for (int i = 0; i <= n; ++i) {
        curr[0] = i; // Only use characters from `a`

        for (int j = 0; j <= m; ++j) {
            if (i == 0 && j == 0) continue; // Base case already handled
            int k = i + j - 1; // Current index in `c`

            curr[j] = INT_MAX; // Initialize to a large value

            if (i > 0 && a[i - 1] == c[k]) { // Match with `a`
                curr[j] = min(curr[j], prev[j]);
            } else if (i > 0) { // Mismatch with `a`
                curr[j] = min(curr[j], prev[j] + 1);
            }

            if (j > 0 && b[j - 1] == c[k]) { // Match with `b`
                curr[j] = min(curr[j], curr[j - 1]);
            } else if (j > 0) { // Mismatch with `b`
                curr[j] = min(curr[j], curr[j - 1] + 1);
            }
        }

        // Swap `prev` and `curr`
        swap(prev, curr);
    }

    return prev[m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        cout << minChanges(a, b, c) << '\n';
    }

    return 0;
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int minOperations(string a, string b, string c) {
    int n = a.length(), m = b.length(), l = c.length();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(l + 1, INT_MAX)));

    // Base case: If i == n and j == m, cost is 0
    for (int k = 0; k <= l; ++k) {
        dp[n][m][k] = 0;
    }

    // Fill the DP table in reverse (bottom-up)
    for (int i = n; i >= 0; --i) {
        for (int j = m; j >= 0; --j) {
            for (int k = l; k >= 0; --k) {
                if (i == n && j == m) continue; // Already handled base case
                
                if (i < n && j < m) {
                    if (a[i] == b[j]) {
                        if (a[i] == c[k]) {
                            dp[i][j][k] = min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        } else {
                            dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        }
                    } else {
                        if (a[i] == c[k]) {
                            dp[i][j][k] = min(dp[i + 1][j][k + 1], 1 + dp[i][j + 1][k + 1]);
                        } else if (b[j] == c[k]) {
                            dp[i][j][k] = min(1 + dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        } else {
                            dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]);
                        }
                    }
                } else if (i < n) {
                    if (a[i] == c[k]) {
                        dp[i][j][k] = dp[i + 1][j][k + 1];
                    } else {
                        dp[i][j][k] = 1 + dp[i + 1][j][k + 1];
                    }
                } else if (j < m) {
                    if (b[j] == c[k]) {
                        dp[i][j][k] = dp[i][j + 1][k + 1];
                    } else {
                        dp[i][j][k] = 1 + dp[i][j + 1][k + 1];
                    }
                }
            }
        }
    }

    return dp[0][0][0]; // Final result
}

int main(){
    int t;
    cin>>t;
    while(t--){
      
       string a,b,c;
       cin>>a>>b>>c;


     cout<<   minOperations(a,b,c);

   cout<<endl;


     
    }
    return 0;
}

Answer: 1