File size: 9,052 Bytes
f7c0146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
    "id": 3033,
    "name": "apply_operations_to_make_two_strings_equal",
    "difficulty": "Medium",
    "link": "https://leetcode.com/problems/apply-operations-to-make-two-strings-equal/",
    "date": "2023-10-01 00:00:00",
    "task_description": "You are given two **0-indexed** binary strings `s1` and `s2`, both of length `n`, and a positive integer `x`. You can perform any of the following operations on the string `s1` **any** number of times: Choose two indices `i` and `j`, and flip both `s1[i]` and `s1[j]`. The cost of this operation is `x`. Choose an index `i` such that `i < n - 1` and flip both `s1[i]` and `s1[i + 1]`. The cost of this operation is `1`. Return _the **minimum** cost needed to make the strings _`s1`_ and _`s2`_ equal, or return _`-1`_ if it is impossible._ **Note** that flipping a character means changing it from `0` to `1` or vice-versa. **Example 1:** ``` **Input:** s1 = \"1100011000\", s2 = \"0101001010\", x = 2 **Output:** 4 **Explanation:** We can do the following operations: - Choose i = 3 and apply the second operation. The resulting string is s1 = \"110**11**11000\". - Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101**00**1000\". - Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"**0**1010010**1**0\" = s2. The total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible. ``` **Example 2:** ``` **Input:** s1 = \"10110\", s2 = \"00011\", x = 4 **Output:** -1 **Explanation:** It is not possible to make the two strings equal. ``` **Constraints:** `n == s1.length == s2.length` `1 <= n, x <= 500` `s1` and `s2` consist only of the characters `'0'` and `'1'`.",
    "public_test_cases": [
        {
            "label": "Example 1",
            "input": "s1 = \"1100011000\", s2 = \"0101001010\", x = 2",
            "output": "4 "
        },
        {
            "label": "Example 2",
            "input": "s1 = \"10110\", s2 = \"00011\", x = 4",
            "output": "-1 "
        }
    ],
    "private_test_cases": [
        {
            "input": [
                "\"1111111001101010111111101010001110001100101110111011100001001000001001010010010100100101000010010011110011101010100000001011101110011010110111111000101000000100001000000110000010001010111010010100000101010011101100\"",
                "\"0001000110101011011001100110111000101111010101011000011101000001110110010011100111010101110110001010010001101100000010100110101001101101101110001110100111010100101110100101000001001110101011100111001101111111001111\"",
                25
            ],
            "output": -1
        },
        {
            "input": [
                "\"110\"",
                "\"010\"",
                421
            ],
            "output": -1
        },
        {
            "input": [
                "\"01101000000000011111100010000111110100010010100110101100101101111111110110110101111011101110101110111111111010101001101001000100001010001010111100011101100011011010010011000000101100001000111000111010000100010110010110010011011101110011110110110100111110011100000001011110111111011110001001001110010010011101100010101000001100001000011111101110101110101011110101111011110111010000110100101110001000010110000110110011110100101111000011111010001101\"",
                "\"10000110001010101010111101110110101011111110010001001111111111011111001011001010011000001010101100010100011110011111010100011000101110101111011000100011110111101111000011001101101100001111100110001110011010111101001101101110011011001101010101010110101010001100011111101011111001111101011100111100111001100001000001100100100000110001101100100000111111100100000001010001110101001111000001110000111010111000111010011011011000001111101100011110011000\"",
                282
            ],
            "output": -1
        },
        {
            "input": [
                "\"1101001000101001101100000100111111000100011001011111100010100010011101011111000001000011101010010110110000111000000010111101110000100101011101000010001101100000000000010011100100001100100111101001010100000001110100011100010010110100111110010010110001101111110011001101100011000101111010111101101101101001100110110110100011110000100010101110101001011001011111110011101000111111011110101000110010101001001011100001001000011010110001001\"",
                "\"1001101110111100010000000110100011011011000010110101011111010011111001111000101000001100010001111110010000001101101100000101110111001101010010111100010111000111110001101001010001011100101001010010101000111111000100000011101010111111111000010010101010001011101111110111110001011001111011011000001010011101110001001001100001111011110011010000011011101000010000010000100000101111101010101110011101111101101100111101010001001000010010000\"",
                327
            ],
            "output": -1
        },
        {
            "input": [
                "\"01110110111110101110000110101011010110010010111101101001011101110001110101010111010110000101110100101100001100010111111011110100011010100101010110111010011110001000\"",
                "\"10011100110101000110011101000111000110001111011000100011110001111001110000101011101000011011001001111000010111101111001011111111101100001110000111001011111101010001\"",
                336
            ],
            "output": 84
        },
        {
            "input": [
                "\"010110000101011010111001010100100010100001110101111111011101001101010011001101100111011000000100101010001010100100110110101000111010001011010001001101000011100001110011011110011001111011010100110000011101101001010011011010110101011011101011100001100011010111100011101011001001100111101011\"",
                "\"110101010101001001011000111111111101101000110001001101111110010001100100100111101001010000001001110011111001100111011101011111111101101001110101111001111111010010100111110101100100101100010000011101000010110000010111011110001100000110110100111110011111010101101110111010001110110110101011\"",
                410
            ],
            "output": 141
        },
        {
            "input": [
                "\"11001001000110011111100001001110111101110011101001110110001011000001010000100011110111001001010100011101000000111111000011110000011001010010111000011100010001111010001000101100100111000001011110010101010010100000011111111110010001101011000111000011010000000110011101010101001000010101100011110010000010111000111011001100100101100110111011000100000010000110100010001011111000011011010001000001110100111001011010010110101101000000000\"",
                "\"10011000100001001110001111101110100001000111000000101010100000110101110001000011010010111111001001111100010000011011101111001001110000010111111100111000100111000110100111100011110110001101101010100101001011000000100010000000011000100011110111110110010100111000101010000001100001111100010101101111111110110001110001101010100011100111010101110101101011000111011010001110111011110010101011000111101101101101111000100110010110110110001\"",
                408
            ],
            "output": -1
        },
        {
            "input": [
                "\"0000100011100101101101100\"",
                "\"1110111100001010010111111\"",
                94
            ],
            "output": -1
        },
        {
            "input": [
                "01001110110111001110111100001111110101101111000111111000101101111111100100010001010001011100011101101110000100101001111011011000011000110000000000001000000001010001100001100011000111110100100111000000111101010000001100110110011011000110100101",
                "00011011000011000100010111010101110000101001000011110111010000111001010101001110010010110110100001010000010011111010000011000110111111101101011011111010110010111000011010000111101100010101101010001111100110001100001010111011001010001000111100",
                422
            ],
            "output": 120
        },
        {
            "input": [
                "010101011110111010000010100100100000100001010011110101001000011101011010000001100010001001110110110011101001001111111011111010101001110100001110011010100011011101000000010000010000110",
                "001111101001000100111000011100101011101100000010010010111000111001101111110011011111000111000111100000000010011000010010000101110110010110100000000011001011111011000010010000001111010",
                1
            ],
            "output": 50
        }
    ],
    "haskell_template": "minOperations :: String -> String -> Int -> Int\nminOperations s1 s2 x ",
    "ocaml_template": "let minOperations (s1: string) (s2: string) (x: int) : int =  ",
    "scala_template": "def minOperations(s1: String,s2: String,x: Int): Int = { \n    \n}",
    "java_template": "class Solution {\n    public int minOperations(String s1, String s2, int x) {\n        \n    }\n}",
    "python_template": "class Solution(object):\n    def minOperations(self, s1, s2, x):\n        \"\"\"\n        :type s1: str\n        :type s2: str\n        :type x: int\n        :rtype: int\n        \"\"\"\n        "
}